Skip to main content

List

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§

const LENGTH: usize = _

The length of the list, computed at compile time.

Required Associated Types§

type Empty: EmptyList

The type returned by List::empty().

type Head: 'static

The type of head.

type Tail: List

The type of the rest of the list.

type Push<U: 'static>: List

The type of the list after pushing a new value.

type Append<U: List>: List

The style of List appended to Self

type ReverseOnto<U: List>: List

The resulting list when reversing Self onto U.

Required Methods§

fn empty() -> Self::Empty

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

§Examples

See List.

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

Returns a reference to the head.

  • Precondition: The list is nonempty.
§Examples

See List.

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

Returns a reference to the rest of the list.

  • Precondition: The list is nonempty.
§Examples

See List.

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,

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,

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§

fn is_empty(&self) -> bool

Returns true if the list is empty.

§Examples

See List.

fn len(&self) -> usize

Returns the length of the list.

§Examples

See List.

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§

§

impl<H, T> List for (H, T)
where H: 'static, T: List,

§

fn empty() -> <(H, T) as List>::Empty

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

§

fn head(&self) -> &<(H, T) as List>::Head

Borrows the first logical field.

§

fn tail(&self) -> &<(H, T) as List>::Tail

Borrows the remaining logical fields.

§

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,

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,

Moves these fields in reverse order before other.

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

type Empty = ()

§

type Head = H

§

type Tail = T

§

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

§

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

§

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

Implementors§

§

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

§

type Empty = CNil<()>

§

type Head = H

§

type Tail = T

§

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

§

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

§

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

§

impl<T> List for T
where T: EmptyList,

A blanket implementation for EmptyList.

§

const LENGTH: usize = 0

§

type Empty = <T as EmptyList>::RootEmpty

§

type Head = Undefined

§

type Tail = T

§

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

§

type Append<U: List> = U

§

type ReverseOnto<U: List> = U