nested

Struct Nested

Source
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 Strings or Vec<T>s

Implementations§

Source§

impl<T: Collection> Nested<T>

Source

pub fn new() -> Self

Create a new Nested.

Source

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

Source

pub fn push<I: AsRef<Item<T>>>(&mut self, el: I)

Pushes a new item

Source

pub fn pop(&mut self) -> Option<T>

Removes the last element from a Nested and returns it, or None if it is empty.

Source

pub fn extend_empty(&mut self, count: usize)

Extend with count empty elements

Source

pub fn len(&self) -> usize

Returns the number of elements in the Nested.

Source

pub fn data_len(&self) -> usize

Get the total length taken by the data

Source

pub fn is_empty(&self) -> bool

Returns true if self has a length of zero.

Source

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.

Source

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.

Source

pub fn get(&self, index: usize) -> Option<&Item<T>>

Returns a shared reference to the output at this location, if in bounds.

Source

pub fn into_parts(self) -> (Vec<usize>, T)

Converts this Nested into its constituent parts.

Source

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.

Source

pub fn data(&self) -> &T

Returns a reference to the underlying data.

The data is stored contiguously.

Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over Nested elements.

Source

pub fn split_off(&mut self, at: usize) -> Nested<T>

Splits the collection into two at the given index.

Returns a newly allocated Self. self contains elements [0, at), and the returned Self contains elements [at, len).

Note that the capacity of self does not change.

Trait Implementations§

Source§

impl<T: Clone> Clone for Nested<T>

Source§

fn clone(&self) -> Nested<T>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Nested<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Collection, A: AsRef<Item<T>>> Extend<A> for Nested<T>

Source§

fn extend<I>(&mut self, iter: I)
where I: IntoIterator, I::Item: AsRef<Item<T>>,

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T: Collection, A: AsRef<Item<T>>> FromIterator<A> for Nested<T>

Source§

fn from_iter<I: IntoIterator<Item = A>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T: Hash> Hash for Nested<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: Collection> Index<usize> for Nested<T>

Source§

type Output = <T as Index<Range<usize>>>::Output

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T: PartialEq> PartialEq for Nested<T>

Source§

fn eq(&self, other: &Nested<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Eq> Eq for Nested<T>

Source§

impl<T> StructuralPartialEq for Nested<T>

Auto Trait Implementations§

§

impl<T> Freeze for Nested<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Nested<T>
where T: RefUnwindSafe,

§

impl<T> Send for Nested<T>
where T: Send,

§

impl<T> Sync for Nested<T>
where T: Sync,

§

impl<T> Unpin for Nested<T>
where T: Unpin,

§

impl<T> UnwindSafe for Nested<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.