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;
#[inline]
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;
#[inline]
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;
#[inline]
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;
#[inline]
fn into_view(self) -> Self::View {
self.view()
}
}
impl<'a, V: ViewMut<'a>> IntoView for &'a mut V {
type View = V::Type;
#[inline]
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;
}