Struct sid::IdVec

source ·
pub struct IdVec<ID: Identifier, T> { /* private fields */ }
Expand description

Similar to Vec except that it is indexed using an Id rather than an usize index. if the stored type implements Default, IdVec can also use the set(…) method which can grow the vector to accomodate for the requested id.

Implementations§

source§

impl<ID: Identifier, T> IdVec<ID, T>

source

pub fn new() -> Self

Create an empty IdVec

source

pub fn with_capacity(size: ID::Handle) -> Self

Create an IdVec with preallocated storage

source

pub fn from_vec(vec: Vec<T>) -> Self

Create an IdVec by recycling a Vec and its content.

source

pub fn into_vec(self) -> Vec<T>

Consume the IdVec and create a Vec.

source

pub fn as_vec(&self) -> &Vec<T>

Exposes the internal Vec.

source

pub fn len(&self) -> ID::Handle

Number of elements in the IdVec

source

pub fn is_empty(&self) -> bool

Returns true if the vector contains no elements.

source

pub fn as_slice(&self) -> IdSlice<'_, ID, T>

Extracts a slice containing the entire vector.

source

pub fn as_mut_slice(&mut self) -> MutIdSlice<'_, ID, T>

Extracts a mutable slice containing the entire vector.

source

pub fn range(&self, ids: IdRange<ID::Tag, ID::Handle>) -> IdSlice<'_, ID, T>

source

pub fn mut_range( &mut self, ids: IdRange<ID::Tag, ID::Handle> ) -> MutIdSlice<'_, ID, T>

source

pub fn range_from(&self, id: ID) -> IdSlice<'_, ID, T>

source

pub fn mut_range_from(&mut self, id: ID) -> MutIdSlice<'_, ID, T>

source

pub fn range_to(&self, id: ID) -> IdSlice<'_, ID, T>

source

pub fn mut_range_to(&mut self, id: ID) -> MutIdSlice<'_, ID, T>

source

pub fn range_to_inclusive(&self, id: ID) -> IdSlice<'_, ID, T>

source

pub fn mut_range_to_inclusive(&mut self, id: ID) -> MutIdSlice<'_, ID, T>

source

pub fn nth(&self, idx: ID::Handle) -> &T

Return the nth element of the IdVec using an usize index rather than an Id (à la Vec).

source

pub fn nth_mut(&mut self, idx: ID::Handle) -> &mut T

Return the nth element of the IdVec using an usize index rather than an Id (à la Vec).

source

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

Iterate over the elements of the IdVec

source

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

Iterate over the elements of the IdVec

source

pub fn push(&mut self, elt: T) -> ID

Add an element to the IdVec and return its Id. This method can cause the storage to be reallocated.

source

pub fn insert(&mut self, id: ID, elt: T)

Inserts an element at position id within the vector, shifting all elements after it to the right.

source

pub fn insert_slice(&mut self, id: ID, elts: &[T])
where T: Clone,

Insert several elements by cloning them starting at position ’id` and shifting all elements after them to the right.

source

pub fn insert_id_slice(&mut self, id: ID, elts: IdSlice<'_, ID, T>)
where T: Clone,

Insert several elements by cloning them starting at position ’id` and shifting all elements after them to the right.

source

pub fn extend_from_slice(&mut self, elts: &[T])
where T: Clone,

Clones and appends all elements in a slice to the vector.

source

pub fn extend_from_id_slice(&mut self, elts: IdSlice<'_, ID, T>)
where T: Clone,

Clones and appends all elements in a slice to the vector.

source

pub fn reserve(&mut self, additional: ID::Handle)

Reserves capacity for at least additional more elements to be inserted in the given vector.

source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the vector as much as possible.

source

pub fn clear(&mut self)

Drop all of the contained elements and clear the IdVec’s storage.

source

pub fn remove(&mut self, index: ID) -> T

Removes and returns the element at position index within the vector, shifting all elements after it to the left.

source

pub fn swap_remove(&mut self, index: ID) -> T

Removes an element from the vector and returns it. The removed element is replaced by the last element of the vector.

source

pub fn has_id(&self, id: ID) -> bool

source

pub fn first_id(&self) -> Option<ID>

source

pub fn last_id(&self) -> Option<ID>

source

pub fn ids(&self) -> IdRange<ID::Tag, ID::Handle>

source§

impl<ID: Identifier, T: Default> IdVec<ID, T>

source

pub fn set(&mut self, id: ID, val: T)

Set the value for a certain Id, possibly adding default values if the Id’s index is Greater than the size of the underlying vector.

source§

impl<T: Default, ID: Identifier> IdVec<ID, T>

source

pub fn resize(&mut self, size: ID::Handle)

source

pub fn with_len(n: ID::Handle) -> Self

Creates an IdVec with an n elements initialized to Default::default.

Trait Implementations§

source§

impl<ID: Identifier, T: Clone> Clone for IdVec<ID, T>

source§

fn clone(&self) -> Self

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<ID: Identifier, T> Index<ID> for IdVec<ID, T>

§

type Output = T

The returned type after indexing.
source§

fn index<'l>(&'l self, id: ID) -> &'l T

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

impl<ID: Identifier, T> IndexMut<ID> for IdVec<ID, T>

source§

fn index_mut<'l>(&'l mut self, id: ID) -> &'l mut T

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

impl<'l, ID: Identifier, T> IntoIterator for &'l IdVec<ID, T>

§

type Item = &'l T

The type of the elements being iterated over.
§

type IntoIter = Iter<'l, T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Iter<'l, T>

Creates an iterator from a value. Read more
source§

impl<'l, ID: Identifier, T> IntoIterator for &'l mut IdVec<ID, T>

§

type Item = &'l mut T

The type of the elements being iterated over.
§

type IntoIter = IterMut<'l, T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> IterMut<'l, T>

Creates an iterator from a value. Read more
source§

impl<ID: Identifier, T> IntoIterator for IdVec<ID, T>

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> IntoIter<T>

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<ID, T> RefUnwindSafe for IdVec<ID, T>

§

impl<ID, T> Send for IdVec<ID, T>
where ID: Send, T: Send,

§

impl<ID, T> Sync for IdVec<ID, T>
where ID: Sync, T: Sync,

§

impl<ID, T> Unpin for IdVec<ID, T>
where ID: Unpin, T: Unpin,

§

impl<ID, T> UnwindSafe for IdVec<ID, T>
where ID: 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> 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,

§

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>,

§

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>,

§

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.