mod sealed {
pub trait Sealed: Sized {}
pub struct Bounds<T>(T);
impl<T> Sealed for Bounds<T> {}
}
use sealed::{Bounds, Sealed};
pub trait NodesData<Index> {
type Data;
fn node_data(&self, node: Index) -> Self::Data;
}
impl<'a, T, Index> NodesData<Index> for &'a T
where
T: ?Sized + NodesDataLend<Index>,
{
type Data = <T as NodesDataLendGat<'a, Index>>::Data;
#[inline]
#[track_caller]
fn node_data(&self, node: Index) -> Self::Data {
(**self).node_data_lend(node)
}
}
impl<T, Index> NodesData<Index> for &mut T
where
T: ?Sized + NodesData<Index>,
{
type Data = T::Data;
#[inline]
#[track_caller]
fn node_data(&self, node: Index) -> Self::Data {
(**self).node_data(node)
}
}
pub trait NodesDataLend<Index>: for<'this> NodesDataLendGat<'this, Index> {
fn node_data_lend(&self, node: Index) -> <Self as NodesDataLendGat<'_, Index>>::Data;
}
pub trait NodesDataLendGat<'this, Index, ImplicitBounds: Sealed = Bounds<&'this Self>> {
type Data;
}
impl<'this, T, Index> NodesDataLendGat<'this, Index> for &T
where
T: ?Sized + NodesDataLendGat<'this, Index>,
{
type Data = T::Data;
}
impl<T, Index> NodesDataLend<Index> for &T
where
T: ?Sized + NodesDataLend<Index>,
{
#[inline]
#[track_caller]
fn node_data_lend(&self, node: Index) -> <Self as NodesDataLendGat<'_, Index>>::Data {
(**self).node_data_lend(node)
}
}
impl<'this, T, Index> NodesDataLendGat<'this, Index> for &mut T
where
T: ?Sized + NodesDataLendGat<'this, Index>,
{
type Data = T::Data;
}
impl<T, Index> NodesDataLend<Index> for &mut T
where
T: ?Sized + NodesDataLend<Index>,
{
#[inline]
#[track_caller]
fn node_data_lend(&self, node: Index) -> <Self as NodesDataLendGat<'_, Index>>::Data {
(**self).node_data_lend(node)
}
}
pub trait NodesDataLendMut<Index>: for<'this> NodesDataLendMutGat<'this, Index> {
fn node_data_lend_mut(&mut self, node: Index)
-> <Self as NodesDataLendMutGat<'_, Index>>::Data;
}
pub trait NodesDataLendMutGat<'this, Index, ImplicitBounds: Sealed = Bounds<&'this Self>> {
type Data;
}
impl<'this, T, Index> NodesDataLendMutGat<'this, Index> for &mut T
where
T: ?Sized + NodesDataLendMutGat<'this, Index>,
{
type Data = T::Data;
}
impl<T, Index> NodesDataLendMut<Index> for &mut T
where
T: ?Sized + NodesDataLendMut<Index>,
{
#[inline]
#[track_caller]
fn node_data_lend_mut(
&mut self,
node: Index,
) -> <Self as NodesDataLendMutGat<'_, Index>>::Data {
(**self).node_data_lend_mut(node)
}
}