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: 'static>(self, item: U) -> Self::Push<U>;
fn append<U: List>(self, other: U) -> Self::Append<U>;
fn reverse_onto<U: List>(self, other: U) -> Self::ReverseOnto<U>;
// Provided methods
fn is_empty(&self) -> bool { ... }
fn len(&self) -> usize { ... }
fn reverse(self) -> Self::ReverseOnto<Self::Empty>
where Self: Sized { ... }
}Expand description
Represents a finite heterogeneous list with source-ordered heads and tails.
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.
Empty lists have length zero; each nonempty list has one more field than its tail. Borrowed heads and tails remain part of the caller-owned list.
§Examples
See the module tutorial.
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 push<U: 'static>(self, item: U) -> Self::Push<U>
fn push<U: 'static>(self, item: U) -> Self::Push<U>
Pushes a new value onto the front of the list, returning a new list.
§Examples
use cel_runtime::List;
assert_eq!(().push("first").push(7u8), (7, ("first", ())));Sourcefn append<U: List>(self, other: U) -> Self::Append<U>
fn append<U: List>(self, other: U) -> Self::Append<U>
Moves other after this list’s source-ordered fields.
- Complexity: O(n) field moves for n fields in this list.
§Examples
use cel_runtime::*;
assert_eq!(
(1, (2, (3, ()))).append((4, (5, (6, ())))),
(1, (2, (3, (4, (5, (6, ()))))))
);Sourcefn reverse_onto<U: List>(self, other: U) -> Self::ReverseOnto<U>
fn reverse_onto<U: List>(self, other: U) -> Self::ReverseOnto<U>
Moves this list’s reversed fields before other.
- Complexity: O(n) field moves for n fields in this list.
§Examples
See List::reverse.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<H: 'static, T: List> List for (H, T)
impl<H: 'static, T: List> List for (H, T)
Source§fn push<U: 'static>(self, item: U) -> Self::Push<U>
fn push<U: 'static>(self, item: U) -> Self::Push<U>
Moves a new first field and this list into their tuple node.
Source§fn append<U: List>(self, other: U) -> Self::Append<U>
fn append<U: List>(self, other: U) -> Self::Append<U>
Moves these source-ordered fields before other.
- Complexity: O(n) field moves for n fields in this list.
Source§fn reverse_onto<U: List>(self, other: U) -> Self::ReverseOnto<U>
fn reverse_onto<U: List>(self, other: U) -> Self::ReverseOnto<U>
Moves these fields in reverse order before other.
- Complexity: O(n) field moves for n fields in this list.