containers_rs/
generic_containers.rs

1/// Trait for a simple container.
2pub trait Container {
3    /// Get the size of the container.
4    fn len(&self) -> usize;
5}
6
7/// Trait that represents dynamically growing containers.
8pub trait DynamicContainer: Container {
9    /// Reserves capacity for at least `additional` more elements to be
10    /// inserted in the container. The collection may reserve more space to avoid
11    /// frequent reallocations.
12    fn reserve(&mut self, additional: usize);
13
14    /// Shrinks the capacity of the container as much as possible.
15    /// It will drop down as much as possible while maintaining the internal
16    /// rules and possibly leaving some space in accordance with the resize policy.
17    fn shrink_to_fit(&mut self);
18
19    /// Returns the number of elements the container can hold without reallocating.
20    fn capacity(&self) -> usize;
21}