pub trait Collection<T> {
// Required methods
fn push(&mut self, elem: T);
fn extend_from_slice(&mut self, elems: &[T])
where T: Clone;
fn extend<I>(&mut self, elems: I)
where I: IntoIterator<Item = T>;
// Provided method
fn reserve(&mut self, _size: usize) { ... }
}Expand description
This trait is meant to abstract any kind of collection
(i.e. Vec, HashSet).
This is particularly helpful when you want particular behavior
when inserting elements, the Counter struct is a good example
of a custom implementation of the Collection trait, it is used to only
count the number of elements of a set operation.
Required Methods§
Sourcefn extend_from_slice(&mut self, elems: &[T])where
T: Clone,
fn extend_from_slice(&mut self, elems: &[T])where
T: Clone,
Extend the collection by cloning the elements.
Sourcefn extend<I>(&mut self, elems: I)where
I: IntoIterator<Item = T>,
fn extend<I>(&mut self, elems: I)where
I: IntoIterator<Item = T>,
Extend the collection by inserting the elements from the given Iterator.
Provided Methods§
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.