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,
impl<T> List<T>where
T: Obj,
pub fn mutate_at<O>(&mut self, i: Int, f: impl FnOnce(&mut T) -> O) -> Owhere
O: Obj,
pub fn mutate_at<O>(&mut self, i: Int, f: impl FnOnce(&mut T) -> O) -> Owhere
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,
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 index_at(&self, i: impl Into<Int>) -> T
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)
pub fn push(&mut self, t: T)
Push an element to the end of the list.
pub fn pop(&mut self) -> Option<T>
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)
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>
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)
pub fn reverse(&mut self)
Reverse the list.
pub fn subslice_with_length(&self, start: Int, length: Int) -> List<T>
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>)>
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>)>
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>)
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,
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,
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
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
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,
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,
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) -> Awhere
A: Obj,
pub fn fold<A>(self, init: A, f: impl FnMut(A, T) -> A) -> Awhere
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) -> Awhere
A: Obj,
pub fn fold_with_idx<A>(self, init: A, f: impl FnMut(A, Int, T) -> A) -> Awhere
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,
pub fn flat_map<O>(self, f: impl FnMut(T) -> List<O>) -> List<O>where
O: Obj,
Works like map, but flattens nested structure.
Trait Implementations§
impl<T> Copy for List<T>where
T: Copy + Obj,
§impl<'de, T> Deserialize<'de> for List<T>where
T: Obj + Deserialize<'de>,
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>,
fn deserialize<D>(
deserializer: D,
) -> Result<List<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
impl<T> Eq for List<T>where
T: Eq + Obj,
§impl<A> FromIterator<A> for List<A>where
A: Obj,
impl<A> FromIterator<A> for List<A>where
A: Obj,
§fn from_iter<T>(iter: T) -> List<A>where
T: IntoIterator<Item = A>,
fn from_iter<T>(iter: T) -> List<A>where
T: IntoIterator<Item = A>,
§impl<T> IntoIterator for List<T>where
T: Obj,
impl<T> IntoIterator for List<T>where
T: Obj,
§impl<T> Ord for List<T>where
T: Ord + Obj,
impl<T> Ord for List<T>where
T: Ord + Obj,
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
§impl<T> PartialOrd for List<T>where
T: PartialOrd + Obj,
impl<T> PartialOrd for List<T>where
T: PartialOrd + Obj,
§impl<T> Serialize for List<T>where
T: Serialize + Obj,
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,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
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>
impl<T> RefUnwindSafe for List<T>where
GcCow<Vector<T>>: RefUnwindSafe,
impl<T> Unpin for List<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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