Skip to main content

List

Struct List 

pub struct List<T>(pub(crate) GcCow<Vector<T>>)
where
    T: Obj;
Expand description

Garbage-collected Vec-like datastructure implementing Copy. Note that functions which seem to mutate the List, actually clone the list and allocate a new GcCow under the hood.

Tuple Fields§

§0: GcCow<Vector<T>>

Implementations§

§

impl<T> List<T>
where T: Obj,

pub fn iter(&self) -> ConsumingIter<T> ⓘ

An ordered iterator over all elements of List.

§

impl<T> List<T>
where T: Obj,

pub fn new() -> List<T>

Returns an empty List.

pub fn len(&self) -> Int

Returns the number of elements in self.

pub fn is_empty(self) -> bool

Returns true if the list contains no elements.

pub fn first(&self) -> Option<T>

Returns the first element of self or None if self is empty.

pub fn last(&self) -> Option<T>

Returns the last element of self or None if self is empty.

pub fn mutate_at<O>(&mut self, i: Int, f: impl FnOnce(&mut T) -> O) -> O
where O: Obj,

Conceptually equivalent to f(&mut self[i]). Mutates the ith element by giving a mutable ref of it into the function f. The return value of f will be returned from mutate_at.

Instead of actual mutation, a new list is allocated, where only the ith element is changed. Then self is changed so that it points to that new list.

pub fn try_mutate_at<O, E>( &mut self, i: Int, f: impl FnOnce(&mut T) -> NdResult<O, E>, ) -> NdResult<O, E>
where O: Obj,

Like mutate_at, but the closure is fallible

pub fn get(&self, i: Int) -> Option<T>

Returns the ith element of the list.

pub fn set(&mut self, i: Int, t: T)

Sets the ith element of the list.

pub fn index_at(&self, i: impl Into<Int>) -> T

The indexing operator: specr translates a[b] to a.index_at(b).

pub fn push(&mut self, t: T)

Push an element to the end of the list.

pub fn pop(&mut self) -> Option<T>

Pop the element from the end of the list. Returns None is the list was empty.

pub fn push_front(&mut self, t: T)

Push an element to the beginning of the list.

pub fn pop_front(&mut self) -> Option<T>

Pop the element from the beginning of the list. Returns None is the list was empty.

pub fn reverse(&mut self)

Reverse the list.

pub fn append(&mut self, other: List<T>)

Append another list to this list.

pub fn subslice_with_length(&self, start: Int, length: Int) -> List<T>

Conceptually equivalent to self[start..length].

pub fn split_first(&self) -> Option<(T, List<T>)>

Returns the first element and the rest of the list. Returns None if the list is empty.

pub fn split_last(&self) -> Option<(T, List<T>)>

Returns the last element and the rest of the list. Returns None if the list is empty.

pub fn write_subslice_at_index(&mut self, start: Int, src: List<T>)

Conceptually equivalent to self[start..src.len()] = src;

pub fn sort_by_key<K>(&mut self, f: impl FnMut(T) -> K)
where K: Obj + Ord,

Sorts the list with a key extraction function.

pub fn zip<T2>(self, other: List<T2>) -> List<(T, T2)>
where T2: Obj,

Combine two lists to a list of pairs.

pub fn any(self, f: impl FnMut(T) -> bool) -> bool

Tests if any element of the list matches a predicate.

pub fn all(self, f: impl FnMut(T) -> bool) -> bool

Tests if all elements of the list matches a predicate.

pub fn map<O>(self, f: impl FnMut(T) -> O) -> List<O>
where O: Obj,

Applies f to each element of the list and returns the outputs as another list.

pub fn map_with_idx<O>(self, f: impl FnMut(Int, T) -> O) -> List<O>
where O: Obj,

Applies f pointwise to each element of the list, also passing it the index of the element in the list.

pub fn fold<A>(self, init: A, f: impl FnMut(A, T) -> A) -> A
where A: Obj,

Fold over the list with the given initial value and step function.

pub fn fold_with_idx<A>(self, init: A, f: impl FnMut(A, Int, T) -> A) -> A
where A: Obj,

Fold over the list with the given initial value and step function; the step function also has access to where in the list we are.

pub fn flat_map<O>(self, f: impl FnMut(T) -> List<O>) -> List<O>
where O: Obj,

Works like map, but flattens nested structure.

pub fn try_map<O, E>( self, f: impl FnMut(T) -> E, ) -> <<E as Try>::Residual as Residual<List<O>>>::TryType
where O: Obj, E: Try<Output = O>, <E as Try>::Residual: Residual<List<O>>,

Applies f to each element of the list and returns the successful outputs as another lists. If at least one call to f failed its error is returned instead.

Trait Implementations§

§

impl<T> Clone for List<T>
where T: Clone + Obj,

§

fn clone(&self) -> List<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<T> Copy for List<T>
where T: Copy + Obj,

§

impl<T> Debug for List<T>
where T: Debug + Obj,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<T> Default for List<T>
where T: Obj,

§

fn default() -> List<T>

Returns the “default value” for a type. Read more
§

impl<'de, T> Deserialize<'de> for List<T>
where T: Obj + Deserialize<'de>,

§

fn deserialize<D>( deserializer: D, ) -> Result<List<T>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl<T> Eq for List<T>
where T: Eq + Obj,

§

impl<A> FromIterator<A> for List<A>
where A: Obj,

§

fn from_iter<T>(iter: T) -> List<A>
where T: IntoIterator<Item = A>,

Creates a value from an iterator. Read more
§

impl<T> Hash for List<T>
where T: Hash + Obj,

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl<T> IntoIterator for List<T>
where T: Obj,

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = ConsumingIter<T>

Which kind of iterator are we turning this into?
§

fn into_iter(self) -> <List<T> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
§

impl<T> Ord for List<T>
where T: Ord + Obj,

§

fn cmp(&self, other: &List<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
§

impl<T> PartialEq for List<T>
where T: PartialEq + Obj,

§

fn eq(&self, other: &List<T>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl<T> PartialOrd for List<T>
where T: PartialOrd + Obj,

§

fn partial_cmp(&self, other: &List<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl<T> Serialize for List<T>
where T: Serialize + Obj,

§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl<T> StructuralPartialEq for List<T>
where T: PartialEq + Obj,

Auto Trait Implementations§

§

impl<T> !Send for List<T>

§

impl<T> !Sync for List<T>

§

impl<T> Freeze for List<T>
where GcCow<Vector<T>>: Freeze,

§

impl<T> RefUnwindSafe for List<T>
where GcCow<Vector<T>>: RefUnwindSafe,

§

impl<T> Unpin for List<T>
where GcCow<Vector<T>>: Unpin,

§

impl<T> UnsafeUnpin for List<T>
where GcCow<Vector<T>>: UnsafeUnpin,

§

impl<T> UnwindSafe for List<T>
where GcCow<Vector<T>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<N> NodeTrait for N
where N: Copy + Ord + Hash,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more