rok::core::collections::list
rok::core::collections::list - List<T>, a growable array (stdlib
spec 2.9.2): one object holding the length, the capacity and the
current element buffer, swapped for a bigger one on growth. The buffer has one
slot past the capacity that is never written: a zero T that vacated
slots are overwritten with, so the list keeps no removed value alive.
Structs
List
pub struct List<T>pub const fn join(self, sep: str) -> strThe items with
sepbetween each two:["a", "b"].join(", ").pub const fn new() -> List<T>pub const fn with_capacity(cap: usize) -> List<T>pub const fn len(self) -> usizepub const fn is_empty(self) -> boolpub const fn capacity(self) -> usizepub const fn reserve(self, additional: usize)Room for
additionalmore elements (doubling).pub const fn shrink_to_fit(self)Capacity cut down to the length.
pub const fn reverse(self)The elements in reverse order, in place.
pub const fn extend<I: IntoIterator<Item = T>>(self, items: I)Push every item of
items, in order.pub const fn push(self, x: T)pub const fn pop(self) -> T | nonepub const fn get(self, idx: usize) -> T | noneElement
idx, ornoneout of bounds.pub const fn set(self, idx: usize, x: T) throws (IndexError)Overwrite element
idx; throws out of bounds (xs[idx] = xpanics instead).pub const fn first(self) -> T | nonepub const fn last(self) -> T | nonepub const fn insert(self, idx: usize, x: T)pub const fn remove(self, idx: usize) -> Tpub const fn clear(self)pub const fn truncate(self, len: usize)Keep the first
lenelements (no change if there are fewer).pub const fn drain(self, r: Range<usize>) -> List<T>Remove the elements in
rand return them, in order; the rest close up. Panics ifris reversed or ends past the length.pub const unsafe fn set_len(self, n: usize)Set the length to
n(at most the capacity) without writing elements, for a buffer filled in place: elements past the old length hold whatever the storage held (zero: vacated slots are zeroed). Shrinking this way leaves the cut elements in place.pub const fn iter(self) -> ListIter<T>pub const fn sort(self)Ascending, stable.
pub const fn sort_by(self, cmp: fn(T, T) -> rok::core::cmp::Ordering)Stable bottom-up merge sort by
cmp: O(n log n), n extra slots.
Trait implementations 16
impl<T> !Sync for List<T>impl<T> IntoIterator for List<T>impl<T> Default for List<T>impl<T: Clone> Clone for List<T>impl<T> Index<usize> for List<T>impl<T> IndexSet<usize> for List<T>impl<T> FromIterator<T> for List<T>impl<T: PartialEq> PartialEq for List<T>impl<T: Eq> Eq for List<T>impl<T: PartialEq + PartialOrd> PartialOrd for List<T>impl<T: Ord> Ord for List<T>impl<T: Hash> Hash for List<T>impl<T: Debug> Debug for List<T>impl<T> AddAssign<T> for List<T>impl<T> AddAssign<List<T>> for List<T>impl<T> Transfer for List<T>
ListIter
pub struct ListIter<T>xs.iter() / for x in xs: walks a list front to back. Its state
is its own (next(ref self), 2.7.1): a copy walks on its own.
Trait implementations 3
impl<T> Iterator for ListIter<T>impl<T> DoubleEndedIterator for ListIter<T>impl<T> ExactSizeIterator for ListIter<T>
Type aliases
ListIntoIter
pub type ListIntoIter<T> = ListIter<T>What xs.into_iter() returns (2.9.2): the same walk as iter.
Functions
list_literal
pub const fn list_literal<T>(items: ...T) -> List<T>[a, b, c] (refs-lang 6.5.1): a List - a fixed array only in a
[T; N] slot, which the compiler builds itself.