Skip to main content

Collection

Trait Collection 

Source
pub trait Collection:
    CollectionBase
    + Default
    + FromIterator<Self::Item>
    + Extend<Self::Item> {
    // Required method
    fn with_capacity(capacity: usize) -> Self;
}
Expand description

Trait implemented by collections with a default constructor and iterator support.

with_capacity() reserves space for the requested number of items for sequences, heaps, sets and maps, or bytes for strings. BTreeSet, BTreeMap and LinkedList cannot reserve capacity and ignore the argument, as do fixed-capacity collections, whose capacity is a part of the type.

An empty collection is created with Default::default().

Required Methods§

Source

fn with_capacity(capacity: usize) -> Self

Creates a new collection with the requested capacity where supported.

The capacity must not come from an untrusted source: growable collections panic or abort if it cannot be allocated. Create an empty collection and use CollectionCapacity::try_reserve instead.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Collection for AsciiString

Available on crate feature ascii only.
Source§

fn with_capacity(capacity: usize) -> Self

Source§

impl Collection for String

Available on crate feature alloc only.
Source§

fn with_capacity(capacity: usize) -> Self

Source§

impl<K: Eq + Hash, V, S: BuildHasher + Default, const N: usize> Collection for IndexMap<K, V, S, N>

Available on crate feature heapless only.
Source§

fn with_capacity(_capacity: usize) -> Self

The capacity is fixed by the type, so this argument is ignored.

Source§

impl<K: Eq + Hash, V, S: BuildHasher + Default> Collection for HashMap<K, V, S>

Available on crate feature std only.
Source§

fn with_capacity(capacity: usize) -> Self

Source§

impl<K: Eq + Hash, V, S: BuildHasher + Default> Collection for HashMap<K, V, S>

Available on crate feature hashbrown only.
Source§

fn with_capacity(capacity: usize) -> Self

Source§

impl<K: Eq + Hash, V, S: BuildHasher + Default> Collection for IndexMap<K, V, S>

Available on crate feature indexmap only.
Source§

fn with_capacity(capacity: usize) -> Self

Source§

impl<K: Ord, V> Collection for BTreeMap<K, V>

Available on crate feature alloc only.
Source§

fn with_capacity(_capacity: usize) -> Self

B-tree collections cannot reserve capacity, so this argument is ignored.

Source§

impl<T, LenT: LenType, const N: usize> Collection for Vec<T, N, LenT>

Available on crate feature heapless only.
Source§

fn with_capacity(_capacity: usize) -> Self

The capacity is fixed by the type, so this argument is ignored.

Source§

impl<T: Eq + Hash, S: BuildHasher + Default, const N: usize> Collection for IndexSet<T, S, N>

Available on crate feature heapless only.
Source§

fn with_capacity(_capacity: usize) -> Self

The capacity is fixed by the type, so this argument is ignored.

Source§

impl<T: Eq + Hash, S: BuildHasher + Default> Collection for HashSet<T, S>

Available on crate feature std only.
Source§

fn with_capacity(capacity: usize) -> Self

Source§

impl<T: Eq + Hash, S: BuildHasher + Default> Collection for HashSet<T, S>

Available on crate feature hashbrown only.
Source§

fn with_capacity(capacity: usize) -> Self

Source§

impl<T: Eq + Hash, S: BuildHasher + Default> Collection for IndexSet<T, S>

Available on crate feature indexmap only.
Source§

fn with_capacity(capacity: usize) -> Self

Source§

impl<T: Ord> Collection for BTreeSet<T>

Available on crate feature alloc only.
Source§

fn with_capacity(_capacity: usize) -> Self

B-tree collections cannot reserve capacity, so this argument is ignored.

Source§

impl<T: Ord> Collection for BinaryHeap<T>

Available on crate feature alloc only.
Source§

fn with_capacity(capacity: usize) -> Self

Source§

impl<T> Collection for LinkedList<T>

Available on crate feature alloc only.
Source§

fn with_capacity(_capacity: usize) -> Self

Source§

impl<T> Collection for Vec<T>

Available on crate feature alloc only.
Source§

fn with_capacity(capacity: usize) -> Self

Source§

impl<T> Collection for VecDeque<T>

Available on crate feature alloc only.
Source§

fn with_capacity(capacity: usize) -> Self

Implementors§