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§
Sourcefn with_capacity(capacity: usize) -> Self
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.
impl Collection for AsciiString
ascii only.fn with_capacity(capacity: usize) -> Self
Source§impl Collection for String
Available on crate feature alloc only.
impl Collection for String
alloc only.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.
impl<K: Eq + Hash, V, S: BuildHasher + Default, const N: usize> Collection for IndexMap<K, V, S, N>
heapless only.Source§fn with_capacity(_capacity: usize) -> Self
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.
impl<K: Eq + Hash, V, S: BuildHasher + Default> Collection for HashMap<K, V, S>
std only.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.
impl<K: Eq + Hash, V, S: BuildHasher + Default> Collection for HashMap<K, V, S>
hashbrown only.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.
impl<K: Eq + Hash, V, S: BuildHasher + Default> Collection for IndexMap<K, V, S>
indexmap only.fn with_capacity(capacity: usize) -> Self
Source§impl<K: Ord, V> Collection for BTreeMap<K, V>
Available on crate feature alloc only.
impl<K: Ord, V> Collection for BTreeMap<K, V>
alloc only.Source§fn with_capacity(_capacity: usize) -> Self
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.
impl<T, LenT: LenType, const N: usize> Collection for Vec<T, N, LenT>
heapless only.Source§fn with_capacity(_capacity: usize) -> Self
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.
impl<T: Eq + Hash, S: BuildHasher + Default, const N: usize> Collection for IndexSet<T, S, N>
heapless only.Source§fn with_capacity(_capacity: usize) -> Self
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.
impl<T: Eq + Hash, S: BuildHasher + Default> Collection for HashSet<T, S>
std only.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.
impl<T: Eq + Hash, S: BuildHasher + Default> Collection for HashSet<T, S>
hashbrown only.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.
impl<T: Eq + Hash, S: BuildHasher + Default> Collection for IndexSet<T, S>
indexmap only.fn with_capacity(capacity: usize) -> Self
Source§impl<T: Ord> Collection for BTreeSet<T>
Available on crate feature alloc only.
impl<T: Ord> Collection for BTreeSet<T>
alloc only.Source§fn with_capacity(_capacity: usize) -> Self
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.
impl<T: Ord> Collection for BinaryHeap<T>
alloc only.fn with_capacity(capacity: usize) -> Self
Source§impl<T> Collection for LinkedList<T>
Available on crate feature alloc only.
impl<T> Collection for LinkedList<T>
alloc only.fn with_capacity(_capacity: usize) -> Self
Source§impl<T> Collection for Vec<T>
Available on crate feature alloc only.
impl<T> Collection for Vec<T>
alloc only.fn with_capacity(capacity: usize) -> Self
Source§impl<T> Collection for VecDeque<T>
Available on crate feature alloc only.
impl<T> Collection for VecDeque<T>
alloc only.