1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
mod map_some;
mod ok_or_else;
pub use self::map_some::MapSome;
pub use self::ok_or_else::OkOrElse;
use finchers_core::Endpoint;
use finchers_core::endpoint::assert_output;
pub trait EndpointOptionExt<T>: Endpoint<Output = Option<T>> + Sized {
fn map_some<F, U>(self, f: F) -> MapSome<Self, F>
where
F: FnOnce(T) -> U + Clone + Send + Sync,
{
assert_output::<_, Option<U>>(self::map_some::new(self, f))
}
fn ok_or_else<F, U>(self, f: F) -> OkOrElse<Self, F>
where
F: FnOnce() -> U + Clone + Send + Sync,
{
assert_output::<_, Result<T, U>>(self::ok_or_else::new(self, f))
}
}
impl<E, T> EndpointOptionExt<T> for E
where
E: Endpoint<Output = Option<T>>,
{
}