From 1a86fb5ca39c366c302942676e1536a3b0b7e514 Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 15 Aug 2022 02:32:47 -0700 Subject: [PATCH] cross: list: fold `MaybeMeta` and `Meta` into one trait --- crates/coremem/src/stim.rs | 2 +- crates/cross/src/compound/list/flat.rs | 9 +++------ crates/cross/src/compound/list/mod.rs | 21 ++++++--------------- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/crates/coremem/src/stim.rs b/crates/coremem/src/stim.rs index 0c402b0..b09ebed 100644 --- a/crates/coremem/src/stim.rs +++ b/crates/coremem/src/stim.rs @@ -45,7 +45,7 @@ impl list::AgnosticVisitor for StimulusListVisitor { impl AbstractStimulus for L where - L: list::MaybeMeta + Sync, + L: list::Meta + Sync, StimulusListVisitor: ListVisitor, { fn at(&self, t_sec: f32, pos: Meters) -> Fields { diff --git a/crates/cross/src/compound/list/flat.rs b/crates/cross/src/compound/list/flat.rs index 695c975..2472b3f 100644 --- a/crates/cross/src/compound/list/flat.rs +++ b/crates/cross/src/compound/list/flat.rs @@ -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 Appendable for Node } } -impl MaybeMeta for Null { +impl Meta for Null { type Length = P0; } -impl Meta for Node { - type Length = P1; -} impl Meta for Node { type Length = PNext; } diff --git a/crates/cross/src/compound/list/mod.rs b/crates/cross/src/compound/list/mod.rs index e389804..c2b3985 100644 --- a/crates/cross/src/compound/list/mod.rs +++ b/crates/cross/src/compound/list/mod.rs @@ -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 { /// convenience to lookup the type of the element at index `P` of list `L`. pub type ElementAt = >::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 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 { 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: PartialListVisitor::Length> {} +pub trait ListVisitor: PartialListVisitor::Length> {} -impl ListVisitor for V +impl ListVisitor for V where - V: PartialListVisitor::Length> + V: PartialListVisitor::Length> {} /// user-facing API to visit a list pub fn visit(l: &L, v: &mut V) where - L: MaybeMeta, + L: Meta, V: ListVisitor, { v.visit_partial(l)