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
38
39
40
41
42
43
44
45
46
47
48
use core::hash::Hash;
use failure::Fail;
pub trait ErrorBase<Val: ?Sized = ()>: Fail + Into<&'static str> + Copy + Eq + Hash {
type With: ?Sized + ErrorWith<Val, Without = Self>;
fn val(self, val: Val) -> Self::With where Val: Sized;
}
pub trait ErrorWith<Val: ?Sized> {
type Without: Fail;
fn as_error(&self) -> Self::Without;
fn as_value(&self) -> &Val;
fn into_value(self) -> Val where Self: Sized, Val: Sized;
fn into_error(self) -> Self::Without where Self: Sized, Val: Sized {
self.as_error()
}
fn map<F, Ret>(self, f: F) -> <Self::Without as ErrorBase<Ret>>::With
where
Self: Sized,
Val: Sized,
F: Fn(Val) -> Ret,
Self::Without: ErrorBase<Ret>,
<Self::Without as ErrorBase<Ret>>::With: Sized,
{
let err = self.as_error();
err.val(f(self.into_value()))
}
}