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
36
37
pub trait ResultOps {
type Item;
type Error;
fn handle_err<F>(self, f:F) -> Option<Self::Item> where F : FnOnce(Self::Error);
}
pub trait ResultUnwrapBoth {
type Item;
fn unwrap_both(self) -> Self::Item;
}
impl<T,E> ResultOps for Result<T,E> {
type Item = T;
type Error = E;
fn handle_err<F>(self, f:F) -> Option<Self::Item> where F : FnOnce(Self::Error) {
self.map_err(f).ok()
}
}
impl<T> ResultUnwrapBoth for Result<T,T> {
type Item = T;
fn unwrap_both(self) -> Self::Item {
match self {
Ok (t) => t,
Err (t) => t
}
}
}