zed/crates/theme_importer/src/util.rs
2023-11-03 10:54:12 -04:00

11 lines
312 B
Rust

use anyhow::Result;
pub trait Traverse<T, U> {
fn traverse(self, f: impl FnOnce(T) -> Result<U>) -> Result<Option<U>>;
}
impl<T, U> Traverse<T, U> for Option<T> {
fn traverse(self, f: impl FnOnce(T) -> Result<U>) -> Result<Option<U>> {
self.map_or(Ok(None), |value| f(value).map(Some))
}
}