coremem_types: list: simplify the IntoList trait

This commit is contained in:
2022-07-21 14:11:42 -07:00
parent 90127e3f02
commit d6ebf968b2

View File

@@ -62,41 +62,36 @@ impl<E0, E1, E2, E3, T> Indexable<P3> for Node<E0, Node<E1, Node<E2, Node<E3, T>
} }
pub trait IntoList { pub trait IntoList {
type Head; type List;
type Tail; fn into_list(self) -> Self::List;
fn into_list(self) -> Node<Self::Head, Self::Tail>;
} }
pub type List<Args> = Node<<Args as IntoList>::Head, <Args as IntoList>::Tail>; pub type List<Args> = <Args as IntoList>::List;
impl<E0> IntoList for (E0,) { impl<E0> IntoList for (E0,) {
type Head = E0; type List = Node<E0, Null>;
type Tail = Null; fn into_list(self) -> Self::List {
fn into_list(self) -> Node<Self::Head, Self::Tail> {
Node::new(self.0, Null) Node::new(self.0, Null)
} }
} }
impl<E0, E1> IntoList for (E0, E1) { impl<E0, E1> IntoList for (E0, E1) {
type Head = E0; type List = Node<E0, <(E1,) as IntoList>::List>;
type Tail = Node<E1, Null>; fn into_list(self) -> Self::List {
fn into_list(self) -> Node<Self::Head, Self::Tail> {
Node::new(self.0, (self.1,).into_list()) Node::new(self.0, (self.1,).into_list())
} }
} }
impl<E0, E1, E2> IntoList for (E0, E1, E2) { impl<E0, E1, E2> IntoList for (E0, E1, E2) {
type Head = E0; type List = Node<E0, <(E1, E2) as IntoList>::List>;
type Tail = Node<E1, Node<E2, Null>>; fn into_list(self) -> Self::List {
fn into_list(self) -> Node<Self::Head, Self::Tail> {
Node::new(self.0, (self.1, self.2).into_list()) Node::new(self.0, (self.1, self.2).into_list())
} }
} }
impl<E0, E1, E2, E3> IntoList for (E0, E1, E2, E3) { impl<E0, E1, E2, E3> IntoList for (E0, E1, E2, E3) {
type Head = E0; type List = Node<E0, <(E1, E2, E3) as IntoList>::List>;
type Tail = Node<E1, Node<E2, Node<E3, Null>>>; fn into_list(self) -> Self::List {
fn into_list(self) -> Node<Self::Head, Self::Tail> {
Node::new(self.0, (self.1, self.2, self.3).into_list()) Node::new(self.0, (self.1, self.2, self.3).into_list())
} }
} }