Skip to main content

List

Trait List 

Source
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§

Source

const LENGTH: usize = _

The length of the list, computed at compile time.

Required Associated Types§

Source

type Empty: EmptyList

The type returned by List::empty().

Source

type Head: 'static

The type of head.

Source

type Tail: List

The type of the rest of the list.

Source

type Push<U: 'static>: List

The type of the list after pushing a new value.

Source

type Append<U: List>: List

The style of List appended to Self

Source

type ReverseOnto<U: List>: List

The resulting list when reversing Self onto U.

Required Methods§

Source

fn empty() -> Self::Empty

Returns a new empty list that can be used to create a list with the same characteristics.

§Examples

See List.

Source

fn head(&self) -> &Self::Head

Returns a reference to the head.

  • Precondition: The list is nonempty.
§Examples

See List.

Source

fn tail(&self) -> &Self::Tail

Returns a reference to the rest of the list.

  • Precondition: The list is nonempty.
§Examples

See List.

Source

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", ())));
Source

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, ()))))))
);
Source

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§

Source

fn is_empty(&self) -> bool

Returns true if the list is empty.

§Examples

See List.

Source

fn len(&self) -> usize

Returns the length of the list.

§Examples

See List.

Source

fn reverse(self) -> Self::ReverseOnto<Self::Empty>
where Self: Sized,

Moves this list’s fields into opposite source order.

  • Complexity: O(n) field moves for n fields.
§Examples

See List.

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)

Source§

fn empty() -> Self::Empty

Constructs an empty tuple-list root without accessing these fields.

Source§

fn head(&self) -> &Self::Head

Borrows the first logical field.

Source§

fn tail(&self) -> &Self::Tail

Borrows the remaining logical fields.

Source§

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>

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>

Moves these fields in reverse order before other.

  • Complexity: O(n) field moves for n fields in this list.
Source§

type Empty = ()

Source§

type Head = H

Source§

type Tail = T

Source§

type Push<U: 'static> = (U, (H, T))

Source§

type Append<U: List> = <<T as List>::Append<U> as List>::Push<H>

Source§

type ReverseOnto<U: List> = <T as List>::ReverseOnto<<U as List>::Push<H>>

Implementors§

Source§

impl<H: 'static, T: List + CStackListHeadLimit> List for CStackList<H, T>

Source§

type Empty = CNil<()>

Source§

type Head = H

Source§

type Tail = T

Source§

type Push<U: 'static> = CStackList<U, CStackList<H, T>>

Source§

type Append<U: List> = <<T as List>::Append<U> as List>::Push<H>

Source§

type ReverseOnto<U: List> = <T as List>::ReverseOnto<<U as List>::Push<H>>

Source§

impl<T: EmptyList> List for T

A blanket implementation for EmptyList.

Source§

const LENGTH: usize = 0

Source§

type Empty = <T as EmptyList>::RootEmpty

Source§

type Head = Undefined

Source§

type Tail = T

Source§

type Push<U: 'static> = <T as EmptyList>::PushFirst<U>

Source§

type Append<U: List> = U

Source§

type ReverseOnto<U: List> = U