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)
}
}