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

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§

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.

Source

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

Returns a reference to the head.

Source

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

Returns a reference to the rest of the 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.

Source

fn append<U: List>(self, other: U) -> Self::Append<U>

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

fn reverse_onto<U: List>(self, other: U) -> Self::ReverseOnto<U>

Reverse Self and append the result to other.

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true if the list is empty.

Source

fn len(&self) -> usize

Returns the length of the list.

Source

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".

Implementations on Foreign Types§

Source§

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

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

Source§

fn empty() -> Self::Empty

Source§

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

Source§

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

Source§

fn push<U: 'static>(self, item: U) -> Self::Push<U>

Source§

fn append<U: List>(self, other: U) -> Self::Append<U>

Source§

fn reverse_onto<U: List>(self, other: U) -> Self::ReverseOnto<U>

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