1pub trait Index<T> {
6 type Output<'a>
8 where
9 Self: 'a;
10
11 fn index(&self, idx: T) -> Self::Output<'_>;
13}
14
15pub trait IndexMut<T>: Index<T> {
18 type OutputMut<'a>
20 where
21 Self: 'a;
22
23 fn index_mut(&mut self, idx: T) -> Self::OutputMut<'_>;
25}
26
27impl<T: ?Sized, I> Index<I> for T
28where
29 T: core::ops::Index<I>,
30 T::Output: 'static,
31{
32 type Output<'a> = &'a <T as core::ops::Index<I>>::Output
33 where
34 Self: 'a;
35
36 fn index(&self, idx: I) -> Self::Output<'_> {
37 <Self as core::ops::Index<I>>::index(self, idx)
38 }
39}
40
41impl<T: ?Sized, I> IndexMut<I> for T
42where
43 T: core::ops::IndexMut<I>,
44 T::Output: 'static,
45{
46 type OutputMut<'a> = &'a mut <T as core::ops::Index<I>>::Output
47 where
48 Self: 'a;
49
50 fn index_mut(&mut self, idx: I) -> Self::OutputMut<'_> {
51 <Self as core::ops::IndexMut<I>>::index_mut(self, idx)
52 }
53}