Struct libspecr::List

source ·
pub struct List<T: Obj>(/* private fields */);
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.

Implementations§

source§

impl<T: Obj> List<T>

source

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

An ordered iterator over all elements of List.

source§

impl<T: Obj> List<T>

source

pub fn new() -> Self

Returns an empty List.

source

pub fn len(&self) -> Int

Returns the number of elements in self.

source

pub fn is_empty(self) -> bool

Returns true if the list contains no elements.

source

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

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

source

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

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

source

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

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.

source

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

Like mutate_at, but the closure is fallible

source

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

Returns the ith element of the list.

source

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

Sets the ith element of the list.

source

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

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

source

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

Push an element to the end of the list.

source

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

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

source

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

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

source

pub fn reverse(&mut self)

Reverse the list.

source

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

Conceptually equivalent to self[start..length].

source

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

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

source

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

Sorts the list with a key extraction function.

source

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

Combine two lists to a list of pairs.

source

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

Tests if any element of the list matches a predicate.

source

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

Tests if all elements of the list matches a predicate.

source

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

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

source

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

Works like map, but flattens nested structure.

source

pub fn try_map<O: Obj, E>( self, f: impl FnMut(T) -> E, ) -> <<E as Try>::Residual as Residual<List<O>>>::TryType
where 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§

source§

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

source§

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

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

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

source§

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

Formats the value using the given formatter. Read more
source§

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

source§

fn default() -> Self

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

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

source§

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

Creates a value from an iterator. Read more
source§

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

source§

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

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

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

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = ConsumingIter<T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

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

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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

source§

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

source§

impl<T: Obj> StructuralPartialEq for List<T>

Auto Trait Implementations§

§

impl<T> Freeze for List<T>

§

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

§

impl<T> !Send for List<T>

§

impl<T> !Sync for List<T>

§

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

§

impl<T> UnwindSafe for List<T>

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
source§

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

source§

fn vzip(self) -> V