cross: list: fold MaybeMeta
and Meta
into one trait
This commit is contained in:
@@ -45,7 +45,7 @@ impl<S: AbstractStimulus> list::AgnosticVisitor<S> for StimulusListVisitor {
|
||||
|
||||
impl<L> AbstractStimulus for L
|
||||
where
|
||||
L: list::MaybeMeta + Sync,
|
||||
L: list::Meta + Sync,
|
||||
StimulusListVisitor: ListVisitor<L>,
|
||||
{
|
||||
fn at(&self, t_sec: f32, pos: Meters) -> Fields {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
use crate::compound::list::{Indexable, MaybeMeta, Meta};
|
||||
use crate::compound::peano::{P0, P1, Peano, PNext};
|
||||
use crate::compound::list::{Indexable, Meta};
|
||||
use crate::compound::peano::{P0, Peano, PNext};
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
@@ -291,13 +291,10 @@ impl<H, T, E> Appendable<E> for Node<H, T>
|
||||
}
|
||||
}
|
||||
|
||||
impl MaybeMeta for Null {
|
||||
impl Meta for Null {
|
||||
type Length = P0;
|
||||
}
|
||||
|
||||
impl<H> Meta for Node<H, Null> {
|
||||
type Length = P1;
|
||||
}
|
||||
impl<H, T: Meta> Meta for Node<H, T> {
|
||||
type Length = PNext<T::Length>;
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
use crate::compound::peano::{Peano, PeanoNonZero, P0, PNext};
|
||||
use crate::compound::peano::{Peano, P0, PNext};
|
||||
|
||||
mod flat;
|
||||
// mod linked;
|
||||
@@ -23,20 +23,11 @@ pub trait Indexable<P: Peano> {
|
||||
/// convenience to lookup the type of the element at index `P` of list `L`.
|
||||
pub type ElementAt<P, L> = <L as Indexable<P>>::Element;
|
||||
|
||||
/// implemented by any List.
|
||||
/// implemented by any List (including the Null, empty list)
|
||||
pub trait Meta {
|
||||
type Length: PeanoNonZero;
|
||||
}
|
||||
|
||||
/// implemented by any List, or Null (empty list)
|
||||
pub trait MaybeMeta {
|
||||
type Length: Peano;
|
||||
}
|
||||
|
||||
impl<M: Meta> MaybeMeta for M {
|
||||
type Length = M::Length;
|
||||
}
|
||||
|
||||
/// implement on your own type for all `N` of a given list if you want to be able to walk the list.
|
||||
pub trait Visitor<N: Peano, Arg> {
|
||||
fn visit(&mut self, a: &Arg);
|
||||
@@ -79,17 +70,17 @@ where
|
||||
}
|
||||
|
||||
/// marker trait for a type which can visit every element in the list `L`.
|
||||
pub trait ListVisitor<L: MaybeMeta>: PartialListVisitor<L, <L as MaybeMeta>::Length> {}
|
||||
pub trait ListVisitor<L: Meta>: PartialListVisitor<L, <L as Meta>::Length> {}
|
||||
|
||||
impl<L: MaybeMeta, V> ListVisitor<L> for V
|
||||
impl<L: Meta, V> ListVisitor<L> for V
|
||||
where
|
||||
V: PartialListVisitor<L, <L as MaybeMeta>::Length>
|
||||
V: PartialListVisitor<L, <L as Meta>::Length>
|
||||
{}
|
||||
|
||||
/// user-facing API to visit a list
|
||||
pub fn visit<L, V>(l: &L, v: &mut V)
|
||||
where
|
||||
L: MaybeMeta,
|
||||
L: Meta,
|
||||
V: ListVisitor<L>,
|
||||
{
|
||||
v.visit_partial(l)
|
||||
|
Reference in New Issue
Block a user