From 35d0e6a96daae510f28e7d3387608f799b78bea8 Mon Sep 17 00:00:00 2001 From: colin Date: Sun, 14 Aug 2022 21:03:49 -0700 Subject: [PATCH] cross: list: add an `Appendable` trait. this isn't tested... hope it works! --- crates/cross/src/compound/list/flat.rs | 22 ++++++++++++++++++++++ crates/cross/src/compound/list/mod.rs | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/crates/cross/src/compound/list/flat.rs b/crates/cross/src/compound/list/flat.rs index d64ebe6..694d445 100644 --- a/crates/cross/src/compound/list/flat.rs +++ b/crates/cross/src/compound/list/flat.rs @@ -269,6 +269,28 @@ impl Prependable for Node { } } +pub type Appended = >::Result; +pub trait Appendable { + // XXX can't move the E parameter inside without Generic Associated Types + type Result; + fn append(self, e: E) -> Self::Result; +} + +impl Appendable for Null { + type Result = Node; + fn append(self, e: E) -> Self::Result { + Node::new(e, Null) + } +} +impl Appendable for Node + where T: Appendable +{ + type Result = Node; + fn append(self, e: E) -> Self::Result { + Node::new(self.head, self.tail.append(e)) + } +} + impl MaybeMeta for Null { type Length = P0; } diff --git a/crates/cross/src/compound/list/mod.rs b/crates/cross/src/compound/list/mod.rs index 9524607..e389804 100644 --- a/crates/cross/src/compound/list/mod.rs +++ b/crates/cross/src/compound/list/mod.rs @@ -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;