default_vec2

Struct DefaultVec

Source
pub struct DefaultVec<T, I = usize>(/* private fields */);
Expand description

A mapping from indexes to values where all indexes initially map to Default::default

It is stored in 2 usizes worth of memory since it doesn’t need to store the length.

It resizes its heap allocation whenever an element that wouldn’t otherwise fit in memory is added and doesn’t ever shrink its memory so it could end of wasting memory if an element is added with a large index and then removed

Implementations§

Source§

impl<T: Default, I: Into<usize>> DefaultVec<T, I>

Source

pub fn get_mut(&mut self, i: I) -> &mut T

Returns mutable access to the element at i

Source

pub fn get(&self, i: I) -> T
where T: Copy,

Returns shared access to the element at i

Source

pub fn clear(&mut self)

Resets all elements to there default value

Source

pub fn capacity(&self) -> usize

Source

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

Returns an iterator over the elements of this list the iterator will have capacity elements

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns a mutable iterator over the elements of this list the iterator will have capacity elements

Trait Implementations§

Source§

impl<T: Clone + Default, I: Into<usize>> Clone for DefaultVec<T, I>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Default, I: Into<usize>> Debug for DefaultVec<T, I>

Source§

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

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

impl<T, I> Default for DefaultVec<T, I>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: ConstDefault, I: Into<usize>> Index<I> for DefaultVec<T, I>

Source§

type Output = T

The returned type after indexing.
Source§

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

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

impl<T: ConstDefault, I: Into<usize>> IndexMut<I> for DefaultVec<T, I>

Source§

fn index_mut(&mut self, index: I) -> &mut Self::Output

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

Auto Trait Implementations§

§

impl<T, I> Freeze for DefaultVec<T, I>

§

impl<T, I> RefUnwindSafe for DefaultVec<T, I>

§

impl<T, I> Send for DefaultVec<T, I>
where I: Send, T: Send,

§

impl<T, I> Sync for DefaultVec<T, I>
where I: Sync, T: Sync,

§

impl<T, I> Unpin for DefaultVec<T, I>
where I: Unpin,

§

impl<T, I> UnwindSafe for DefaultVec<T, I>
where I: UnwindSafe, 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.