pub trait ExtendWithCapacity<T>: Extend<T> {
// Required method
fn with_capacity(capacity: usize) -> Self;
}Expand description
A trait for collections that can be pre-allocated with specific capacity and extended with elements.
This extends the standard Extend trait to provide a uniform interface
for collection types that support capacity pre-allocation.
Pre-allocating capacity can improve performance when the number of elements
is known in advance.
Due to the fact that in Rust iterators, size_hint()
might return (0, None), pre-allocating capacity can be particularly
useful.
§Implementors
- alloc collections:
Vec<T>,String,VecDeque<T>,BinaryHeap<T> - std types (with
stdfeature):OsString,HashMap,HashSet,PathBuf - AHash collections (with
ahash&stdfeatures):AHashMap,AHashSet
Required Methods§
fn with_capacity(capacity: usize) -> Self
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<K, S> ExtendWithCapacity<K> for HashSet<K, S>
Available on crate feature std only.
impl<K, S> ExtendWithCapacity<K> for HashSet<K, S>
Available on crate feature
std only.fn with_capacity(capacity: usize) -> Self
Source§impl<K, S> ExtendWithCapacity<K> for IndexSet<K, S>
Available on crate feature indexmap only.
impl<K, S> ExtendWithCapacity<K> for IndexSet<K, S>
Available on crate feature
indexmap only.fn with_capacity(capacity: usize) -> Self
Source§impl<K, V, S> ExtendWithCapacity<(K, V)> for HashMap<K, V, S>
Available on crate feature std only.
impl<K, V, S> ExtendWithCapacity<(K, V)> for HashMap<K, V, S>
Available on crate feature
std only.fn with_capacity(capacity: usize) -> Self
Source§impl<K, V, S> ExtendWithCapacity<(K, V)> for IndexMap<K, V, S>
Available on crate feature indexmap only.
impl<K, V, S> ExtendWithCapacity<(K, V)> for IndexMap<K, V, S>
Available on crate feature
indexmap only.fn with_capacity(capacity: usize) -> Self
Source§impl<K: Eq + Hash> ExtendWithCapacity<K> for AHashSet<K>
Available on crate feature ahash only.
impl<K: Eq + Hash> ExtendWithCapacity<K> for AHashSet<K>
Available on crate feature
ahash only.fn with_capacity(capacity: usize) -> Self
Source§impl<K: Eq + Hash, V> ExtendWithCapacity<(K, V)> for AHashMap<K, V>
Available on crate feature ahash only.
impl<K: Eq + Hash, V> ExtendWithCapacity<(K, V)> for AHashMap<K, V>
Available on crate feature
ahash only.fn with_capacity(capacity: usize) -> Self
Source§impl<T> ExtendWithCapacity<T> for VecDeque<T>
impl<T> ExtendWithCapacity<T> for VecDeque<T>
fn with_capacity(capacity: usize) -> Self
Source§impl<T> ExtendWithCapacity<T> for String
impl<T> ExtendWithCapacity<T> for String
fn with_capacity(capacity: usize) -> Self
Source§impl<T> ExtendWithCapacity<T> for Vec<T>
impl<T> ExtendWithCapacity<T> for Vec<T>
fn with_capacity(capacity: usize) -> Self
Source§impl<T> ExtendWithCapacity<T> for OsString
Available on crate feature std only.
impl<T> ExtendWithCapacity<T> for OsString
Available on crate feature
std only.fn with_capacity(capacity: usize) -> Self
Source§impl<T: Ord> ExtendWithCapacity<T> for BinaryHeap<T>
impl<T: Ord> ExtendWithCapacity<T> for BinaryHeap<T>
fn with_capacity(capacity: usize) -> Self
Source§impl<T: AsRef<Path>> ExtendWithCapacity<T> for PathBuf
Available on crate feature std only.
impl<T: AsRef<Path>> ExtendWithCapacity<T> for PathBuf
Available on crate feature
std only.