pub struct Nested<T> { /* private fields */ }
Expand description
A two dimensional collection with minimal allocation
T
is the owning underlying container.
For instance, it behaves similarly to Vec<Vec<T>>
or Vec<String>
but
only has 2 internal buffers.
It can be used:
- on your own collection as long as it implements the
Collection
trait. - like a sparse vector
- when you need to collect (move ownership) many
String
s orVec<T>
s
Implementations§
Source§impl<T: Collection> Nested<T>
impl<T: Collection> Nested<T>
Sourcepub fn with_capacity(len: usize, size: usize) -> Self
pub fn with_capacity(len: usize, size: usize) -> Self
Creates a new Nested
with given capacity.
len: the expected item count size: the expected total size taken by all items
Sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Removes the last element from a Nested
and returns it, or None if it is empty.
Sourcepub fn extend_empty(&mut self, count: usize)
pub fn extend_empty(&mut self, count: usize)
Extend with count
empty elements
Sourcepub fn truncate(&mut self, len: usize)
pub fn truncate(&mut self, len: usize)
Shortens the Nested
, keeping the first len elements and dropping the rest.
If len is greater than the vector’s current length, this has no effect.
Note that this method has no effect on the allocated capacity of the vector.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Truncates this Nested
, removing all contents.
While this means the Nested
will have a length of zero, it does not touch its capacity.
Sourcepub fn get(&self, index: usize) -> Option<&Item<T>>
pub fn get(&self, index: usize) -> Option<&Item<T>>
Returns a shared reference to the output at this location, if in bounds.
Sourcepub fn into_parts(self) -> (Vec<usize>, T)
pub fn into_parts(self) -> (Vec<usize>, T)
Converts this Nested
into its constituent parts.
Sourcepub fn indices(&self) -> &[usize]
pub fn indices(&self) -> &[usize]
Returns a reference to the underlying indices.
Each index represents the start of each logical vector beyond the first one.
Trait Implementations§
Source§impl<T: Collection, A: AsRef<Item<T>>> Extend<A> for Nested<T>
impl<T: Collection, A: AsRef<Item<T>>> Extend<A> for Nested<T>
Source§fn extend<I>(&mut self, iter: I)
fn extend<I>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)