[go: up one dir, main page]

Struct IdVec

Source
pub struct IdVec<ID: Identifier, Data> { /* 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, Data> IdVec<ID, Data>

Source

pub fn new() -> IdVec<ID, Data>

Create an empty IdVec

Source

pub fn with_capacity(size: ID::Handle) -> IdVec<ID, Data>

Create an IdVec with preallocated storage

Source

pub fn from_vec(vec: Vec<Data>) -> IdVec<ID, Data>

Create an IdVec by recycling a Vec and its content.

Source

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

Consume the IdVec and create a Vec.

Source

pub fn len(&self) -> usize

Number of elements in the IdVec

Source

pub fn nth(&self, idx: usize) -> &Data

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: usize) -> &mut Data

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

Iterate over the elements of the IdVec

Source

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

Iterate over the elements of the IdVec

Source

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

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

Source

pub fn clear(&mut self)

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

Source§

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

Source

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

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<Data: Default, ID: Identifier> IdVec<ID, Data>

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, Data> Index<ID> for IdVec<ID, Data>

Source§

type Output = Data

The returned type after indexing.
Source§

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

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

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

Source§

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

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

Auto Trait Implementations§

§

impl<ID, Data> Freeze for IdVec<ID, Data>

§

impl<ID, Data> RefUnwindSafe for IdVec<ID, Data>
where ID: RefUnwindSafe, Data: RefUnwindSafe,

§

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

§

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

§

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

§

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