docs

你正在阅读 v0.1.2 的文档。Nabi 0.1.2 已不再提供支持。 最新版本:v0.1.3 →

core::collections::frozen

本页内容

API 参考只有英文版,由标准库源代码中的英文文档注释生成。

FrozenList, FrozenDict and FrozenSet: a collection that no one can change any more, shared between threads without a lock and without a copy.

xs.freeze() takes the collection's storage over in O(1) and leaves xs empty, so a handle the compiler did not see (code in unsafe) changes a new, empty collection, never what the readers read. Only elements that are Send + Sync themselves can be frozen, so nothing reached from a frozen collection can change either.

Structs

FrozenListSource

pub struct FrozenList<T>

A list that never changes: Sync, so threads share one without a lock (a par closure may capture it, a static may hold it, a hand-off leaves it shared). Made by List::freeze; to_list gives a list to change.

  • pub const fn new() -> FrozenList<T>§

    Source

    An empty frozen list.

  • pub const fn len(self) -> usize§

    Source

    The number of elements.

  • pub const fn is_empty(self) -> bool§

    Source

    true when the list has no element.

  • pub const fn get(self, i: usize) -> T | none§

    Source

    Element i, or none out of bounds.

  • pub const fn first(self) -> T | none§

    Source

    The first element; none when empty.

  • pub const fn last(self) -> T | none§

    Source

    The last element; none when empty.

  • pub const fn iter(self) -> ListIter<T>§

    Source

    The elements front to back.

  • pub const fn split_at(self, mid: usize) -> (Slice<T>, Slice<T>)§

    Source

    Views of [0, mid) and [mid, len); panics if mid is past the length.

  • pub const fn windows(self, size: usize) -> slice::Windows<T>§

    Source

    Views of size consecutive elements, sliding by one (size > 0).

  • pub const fn chunks(self, size: usize) -> slice::Chunks<T>§

    Source

    Views of size elements in order, the last one shorter (size > 0): par::map(xs.chunks(n), ..) reads them in parallel.

  • pub const fn to_list(self) -> List<T>§

    Source

    A new list holding the elements, free to change.

  • pub const fn contains(self, x: T) -> bool§

    Source

    true when an element equals x.

  • Source

    The index of x in the sorted list, or none.

Trait implementations 10

FrozenDictSource

pub struct FrozenDict<K, V, S = RandomState>

A dict that never changes: Sync, so threads share one without a lock. Made by Dict::freeze; to_dict gives a dict to change.

  • pub fn new() -> FrozenDict<K, V>§

    Source

    An empty frozen dict.

  • pub const fn len(self) -> usize§

    Source

    The number of entries.

  • pub const fn is_empty(self) -> bool§

    Source

    true when the dict has no entry.

  • pub const fn get(self, k: K) -> V | none§

    Source

    The value under k; none when k is absent.

  • pub const fn get_or(self, k: K, default: V) -> V§

    Source

    The value under k; default when k is absent.

  • pub const fn contains_key(self, k: K) -> bool§

    Source

    true when k has an entry.

  • pub const fn keys(self) -> Keys<K, V, S>§

    Source

    The keys, in insertion order.

  • pub const fn values(self) -> Values<K, V, S>§

    Source

    The values, in insertion order.

  • pub const fn iter(self) -> DictIter<K, V, S>§

    Source

    The (key, value) pairs, in insertion order.

  • pub const fn hasher(self) -> S§

    Source

    What builds the dict's hashers.

  • pub const fn to_dict(self) -> Dict<K, V, S>§

    Source

    A new dict holding the entries, free to change.

Trait implementations 7

FrozenSetSource

pub struct FrozenSet<T, S = RandomState>

A set that never changes: Sync, so threads share one without a lock. Made by Set::freeze; to_set gives a set to change.

  • pub fn new() -> FrozenSet<T>§

    Source

    An empty frozen set.

  • pub const fn len(self) -> usize§

    Source

    The number of members.

  • pub const fn is_empty(self) -> bool§

    Source

    true when the set has no member.

  • pub const fn contains(self, x: T) -> bool§

    Source

    true when x is a member.

  • pub const fn iter(self) -> Keys<T, bool, S>§

    Source

    The members, in insertion order.

  • pub const fn hasher(self) -> S§

    Source

    What builds the set's hashers.

  • pub const fn to_set(self) -> Set<T, S>§

    Source

    A new set holding the members, free to change.

Trait implementations 6