Trait List
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
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§
type Empty: EmptyList
type Empty: EmptyList
The type returned by List::empty().
type Head: 'static
type Head: 'static
The type of head.
type ReverseOnto<U: List>: List
type ReverseOnto<U: List>: List
The resulting list when reversing Self onto U.
Required Methods§
fn 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.
§Examples
use cel_runtime::List;
assert_eq!(().push("first").push(7u8), (7, ("first", ())));fn append<U>(self, other: U) -> Self::Append<U>where
U: List,
fn append<U>(self, other: U) -> Self::Append<U>where
U: List,
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, ()))))))
);fn 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,
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§
§impl<H, T> List for (H, T)where
H: 'static,
T: List,
impl<H, T> List for (H, T)where
H: 'static,
T: List,
§fn empty() -> <(H, T) as List>::Empty
fn empty() -> <(H, T) as List>::Empty
Constructs an empty tuple-list root without accessing these fields.
§fn push<U>(self, item: U) -> <(H, T) as List>::Push<U>where
U: 'static,
fn push<U>(self, item: U) -> <(H, T) as List>::Push<U>where
U: 'static,
Moves a new first field and this list into their tuple node.
§fn append<U>(self, other: U) -> <(H, T) as List>::Append<U>where
U: List,
fn append<U>(self, other: U) -> <(H, T) as List>::Append<U>where
U: List,
Moves these source-ordered fields before other.
- Complexity: O(n) field moves for n fields in this list.
§fn reverse_onto<U>(self, other: U) -> <(H, T) as List>::ReverseOnto<U>where
U: List,
fn reverse_onto<U>(self, other: U) -> <(H, T) as List>::ReverseOnto<U>where
U: List,
Moves these fields in reverse order before other.
- Complexity: O(n) field moves for n fields in this list.