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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
pub trait Viewed {}
pub trait View<'a> {
type Type: Viewed;
fn view(&'a self) -> Self::Type;
}
pub trait ViewMut<'a> {
type Type: Viewed;
fn view_mut(&'a mut self) -> Self::Type;
}
impl<'a, S: ?Sized + 'a + View<'a>> View<'a> for &S {
type Type = S::Type;
fn view(&'a self) -> Self::Type {
<S as View<'a>>::view(*self)
}
}
impl<'a, S: ?Sized + 'a + View<'a>> View<'a> for &mut S {
type Type = S::Type;
fn view(&'a self) -> Self::Type {
<S as View<'a>>::view(*self)
}
}
impl<'a, S: ?Sized + 'a + ViewMut<'a>> ViewMut<'a> for &mut S {
type Type = S::Type;
fn view_mut(&'a mut self) -> Self::Type {
<S as ViewMut<'a>>::view_mut(*self)
}
}
pub trait IntoView {
type View;
fn into_view(self) -> Self::View;
}
impl<'a, V: View<'a>> IntoView for &'a V {
type View = V::Type;
fn into_view(self) -> Self::View {
self.view()
}
}
impl<'a, V: ViewMut<'a>> IntoView for &'a mut V {
type View = V::Type;
fn into_view(self) -> Self::View {
self.view_mut()
}
}
pub trait ViewIterator<'a> {
type Item;
type Iter: Iterator<Item = Self::Item>;
fn view_iter(&'a self) -> Self::Iter;
}
pub trait ViewMutIterator<'a> {
type Item;
type Iter: Iterator<Item = Self::Item>;
fn view_mut_iter(&'a mut self) -> Self::Iter;
}