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
pub trait Index<T> {
type Output<'a>
where
Self: 'a;
fn index(&self, idx: T) -> Self::Output<'_>;
}
pub trait IndexMut<T>: Index<T> {
type OutputMut<'a>
where
Self: 'a;
fn index_mut(&mut self, idx: T) -> Self::OutputMut<'_>;
}
impl<T: ?Sized, I> Index<I> for T
where
T: core::ops::Index<I>,
T::Output: 'static,
{
type Output<'a> = &'a <T as core::ops::Index<I>>::Output
where
Self: 'a;
fn index(&self, idx: I) -> Self::Output<'_> {
<Self as core::ops::Index<I>>::index(self, idx)
}
}
impl<T: ?Sized, I> IndexMut<I> for T
where
T: core::ops::IndexMut<I>,
T::Output: 'static,
{
type OutputMut<'a> = &'a mut <T as core::ops::Index<I>>::Output
where
Self: 'a;
fn index_mut(&mut self, idx: I) -> Self::OutputMut<'_> {
<Self as core::ops::IndexMut<I>>::index_mut(self, idx)
}
}