cross: list: add an Appendable trait.

this isn't tested... hope it works!
This commit is contained in:
2022-08-14 21:03:49 -07:00
parent 6e9b4465cb
commit 35d0e6a96d
2 changed files with 23 additions and 1 deletions

View File

@@ -269,6 +269,28 @@ impl<H, T> Prependable for Node<H, T> {
}
}
pub type Appended<Head, Next> = <Head as Appendable<Next>>::Result;
pub trait Appendable<E> {
// XXX can't move the E parameter inside without Generic Associated Types
type Result;
fn append(self, e: E) -> Self::Result;
}
impl<E> Appendable<E> for Null {
type Result = Node<E, Null>;
fn append(self, e: E) -> Self::Result {
Node::new(e, Null)
}
}
impl<H, T, E> Appendable<E> for Node<H, T>
where T: Appendable<E>
{
type Result = Node<H, T::Result>;
fn append(self, e: E) -> Self::Result {
Node::new(self.head, self.tail.append(e))
}
}
impl MaybeMeta for Null {
type Length = P0;
}

View File

@@ -5,7 +5,7 @@ mod flat;
// mod tuple_consumer;
// pub use tuple_consumer::*;
// pub use linked::*;
pub use flat::{IntoList, Prependable, Prepended};
pub use flat::{IntoList, Appendable, Appended, Prependable, Prepended};
pub use flat::exports::*;
pub type Empty = flat::Null;