cross: list: add some conveniences to query list length and access the first element
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use crate::compound::peano::Peano;
|
use crate::compound::peano::{Peano, P0};
|
||||||
|
|
||||||
mod flat;
|
mod flat;
|
||||||
// mod linked;
|
// mod linked;
|
||||||
@@ -47,6 +47,32 @@ pub trait IndexableExplicit {
|
|||||||
{
|
{
|
||||||
Indexable::set(self, v)
|
Indexable::set(self, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_first(&self) -> <Self as Indexable<P0>>::Element
|
||||||
|
where
|
||||||
|
Self: Indexable<P0>,
|
||||||
|
Self::Element: Copy,
|
||||||
|
{
|
||||||
|
Indexable::get(self)
|
||||||
|
}
|
||||||
|
fn get_first_ref(&self) -> &<Self as Indexable<P0>>::Element
|
||||||
|
where
|
||||||
|
Self: Indexable<P0>,
|
||||||
|
{
|
||||||
|
Indexable::get_ref(self)
|
||||||
|
}
|
||||||
|
fn get_first_mut(&mut self) -> &mut <Self as Indexable<P0>>::Element
|
||||||
|
where
|
||||||
|
Self: Indexable<P0>,
|
||||||
|
{
|
||||||
|
Indexable::get_mut(self)
|
||||||
|
}
|
||||||
|
fn set_first(&mut self, v: Self::Element)
|
||||||
|
where
|
||||||
|
Self: Indexable<P0>,
|
||||||
|
{
|
||||||
|
Indexable::set(self, v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<L> IndexableExplicit for L {}
|
impl<L> IndexableExplicit for L {}
|
||||||
@@ -57,6 +83,9 @@ pub type ElementAt<P, L> = <L as Indexable<P>>::Element;
|
|||||||
/// implemented by any List (including the Null, empty list)
|
/// implemented by any List (including the Null, empty list)
|
||||||
pub trait Meta {
|
pub trait Meta {
|
||||||
type Length: Peano;
|
type Length: Peano;
|
||||||
|
fn len(&self) -> u32 {
|
||||||
|
Self::Length::VALUE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user