pub trait List {
type Empty: EmptyList;
type Head: 'static;
type Tail: List;
type Push<U: 'static>: List;
type Append<U: List>: List;
type ReverseOnto<U: List>: List;
const LENGTH: usize = _;
// Required methods
fn empty() -> Self::Empty;
fn head(&self) -> &Self::Head;
fn tail(&self) -> &Self::Tail;
fn push<U>(self, item: U) -> Self::Push<U>
where U: 'static;
fn append<U>(self, other: U) -> Self::Append<U>
where U: List;
fn reverse_onto<U>(self, other: U) -> Self::ReverseOnto<U>
where U: List;
// Provided methods
fn is_empty(&self) -> bool { ... }
fn len(&self) -> usize { ... }
fn reverse(self) -> Self::ReverseOnto<Self::Empty>
where Self: Sized { ... }
}Expand description
A trait representing a homogeneous list (cons cell) with a head and tail.
The List trait provides a type-safe way to work with lists where each node
contains a value (head) and the remainder of the list (tail). This trait
is implemented for both empty lists and non-empty lists.
Provided Associated Constants§
Required Associated Types§
Sourcetype Empty: EmptyList
type Empty: EmptyList
The type returned by List::empty().
Sourcetype ReverseOnto<U: List>: List
type ReverseOnto<U: List>: List
The resulting list when reversing Self onto U.
Required Methods§
Sourcefn empty() -> Self::Empty
fn empty() -> Self::Empty
Returns a new empty list that can be used to create a list with the same characteristics.
Sourcefn push<U>(self, item: U) -> Self::Push<U>where
U: 'static,
fn push<U>(self, item: U) -> Self::Push<U>where
U: 'static,
Pushes a new value onto the front of the list, returning a new list.
Sourcefn append<U>(self, other: U) -> Self::Append<U>where
U: List,
fn append<U>(self, other: U) -> Self::Append<U>where
U: List,
Append U as the tail of Self.
§Example
use cel_runtime::*;
assert_eq!(
(1, (2, (3, ()))).append((4, (5, (6, ())))),
(1, (2, (3, (4, (5, (6, ()))))))
);Sourcefn reverse_onto<U>(self, other: U) -> Self::ReverseOnto<U>where
U: List,
fn reverse_onto<U>(self, other: U) -> Self::ReverseOnto<U>where
U: List,
Reverse Self and append the result to other.
Provided Methods§
Sourcefn reverse(self) -> Self::ReverseOnto<Self::Empty>where
Self: Sized,
fn reverse(self) -> Self::ReverseOnto<Self::Empty>where
Self: Sized,
Reverse this list, returning a new list with elements in opposite order.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".