core::collections
API 参考只有英文版,由标准库源代码中的英文文档注释生成。
List / Dict / Set / Slice,
Deque, BinaryHeap, SortedDict / SortedSet, and the frozen
(read-only, Sync) List / Dict / Set.
Each collection is a small handle struct over GC buffers (raw):
copying the handle shares the collection, so the mutating methods
take self (not ref self: the handle is what they change). The types
are re-exported here: use core::collections::List.
Modules
broadcastthe element-wise dot operators onList<T>:List op List(same length, else a panic),List op TandT op List(the scalar applies to every element).dequeDeque<T>, a growable ring buffer with O(1) push and pop at both ends.dictDict<K, V, S>, a hash map hashing withS(the process-keyedRandomStateby default), compact: entries are appended to dense key / value / hash arrays, and a power-of-two index of linear-probed slots maps a hash to its entry.frozenFrozenList,FrozenDictandFrozenSet: a collection that no one can change any more, shared between threads without a lock and without a copy.heapBinaryHeap<T>, a priority queue over aListlaid out as an implicit binary tree.listList<T>, a growable array: one object holding the length, the capacity and the current element buffer, swapped for a bigger one on growth.setSet<T, S>, a hash set overDict<T, bool, S>, so it iterates in insertion order.sliceSlice<T>, a zero-copy view; elementiisbuf[start + i * stride], and the view keeps its buffer alive.sortedSortedDict<K, V>andSortedSet<T>: ordered byK: Ord, kept in a B-tree.
Re-exports
deque::{Deque, DequeIter}Source
pub use deque::{Deque, DequeIter}dict::{Dict, Entry, Keys, Values, DictIter}Source
pub use dict::{Dict, Entry, Keys, Values, DictIter}frozen::{FrozenDict, FrozenList, FrozenSet}Source
pub use frozen::{FrozenDict, FrozenList, FrozenSet}FrozenDictA dict that never changes:Sync, so threads share one without a lock.FrozenListA list that never changes:Sync, so threads share one without a lock (aparclosure may capture it, astaticmay hold it, a hand-off leaves it shared).FrozenSetA set that never changes:Sync, so threads share one without a lock.
heap::{BinaryHeap, HeapIter}Source
pub use heap::{BinaryHeap, HeapIter}BinaryHeapA priority queue:new()pops the greatest item first,by_ordering(cmp)the greatest bycmp.HeapIterThe items of a heap, in no particular order.
list::{List, ListIter, ListIntoIter}Source
pub use list::{List, ListIter, ListIntoIter}ListA growable array; copies share one buffer.ListIterxs.iter()/for x in xs: walks a list front to back.ListIntoIterWhatxs.into_iter()returns: the same walk asiter.
set::{Set, SetIter}Source
pub use set::{Set, SetIter}slice::{ChunksMut, Slice, SliceIter, SliceMut, SliceMutIter}Source
pub use slice::{ChunksMut, Slice, SliceIter, SliceMut, SliceMutIter}ChunksMutxs.chunks_mut(size): each chunk is a writable view of its own part of the list, no copy.SliceA zero-copy view of a buffer: elementiisbuf[start + i * stride].SliceIters.iter()/for x in s, in view order.SliceMutA writable view of a list's elements, like Rust's&mut [T]:s[i] = xwrites the list.SliceMutIters.iter()/for x in s: checks the view on every step.
sorted::{KeyRange, SortedDict, SortedIter, SortedKeys, SortedSet, SortedValues}Source
pub use sorted::{KeyRange, SortedDict, SortedIter, SortedKeys, SortedSet, SortedValues}KeyRangeThe bounds of a key range:a..b,a..=b,a..,..b,..=band..implement it, sod.range(3..7)takes any of them.SortedDictA map ordered by key.SortedIterThe entries of aSortedDictin key order (or reversed), within a range.SortedKeysThe keys of aSortedDictin order.SortedSetA set ordered byT: Ord, kept in a B-tree.SortedValuesThe values of aSortedDictin key order.