mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-11 21:13:02 +00:00
11 lines
312 B
Rust
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))
|
|
}
|
|
}
|