pub struct FlattenObjects<T, const CAP: usize> { /* private fields */ }
Expand description

A container that stores numbered objects.

See the crate-level documentation for more details.

CAP is the maximum number of objects that can be held. It also equals the maximum ID that can be assigned plus one. Currently, CAP must not be greater than 1024.

Implementations§

source§

impl<T, const CAP: usize> FlattenObjects<T, CAP>

source

pub const fn new() -> Self

Creates a new empty FlattenObjects.

source

pub const fn capacity(&self) -> usize

Returns the maximum number of objects that can be held.

It also equals the maximum ID that can be assigned plus one.

source

pub const fn count(&self) -> usize

Returns the number of objects that have been added.

source

pub fn is_assigned(&self, id: usize) -> bool

Returns true if the given id is already be assigned.

source

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

Returns the reference of the element with the given id if it already be assigned. Otherwise, returns None.

source

pub fn get_mut(&mut self, id: usize) -> Option<&mut T>

Returns the mutable reference of the element with the given id if it exists. Otherwise, returns None.

source

pub fn add(&mut self, value: T) -> Option<usize>

Add an object and assigns it a unique ID.

Returns the ID if there is one available. Otherwise, returns None.

source

pub fn add_at(&mut self, id: usize, value: T) -> Option<usize>

Add an object and assigns it a specific ID.

Returns the ID if it’s not used by others. Otherwise, returns None.

source

pub fn remove(&mut self, id: usize) -> Option<T>

Removes the object with the given ID.

Returns the object if there is one assigned to the ID. Otherwise, returns None.

After this operation, the ID is freed and can be assigned for next object again.

Auto Trait Implementations§

§

impl<T, const CAP: usize> RefUnwindSafe for FlattenObjects<T, CAP>
where T: RefUnwindSafe,

§

impl<T, const CAP: usize> Send for FlattenObjects<T, CAP>
where T: Send,

§

impl<T, const CAP: usize> Sync for FlattenObjects<T, CAP>
where T: Sync,

§

impl<T, const CAP: usize> Unpin for FlattenObjects<T, CAP>
where T: Unpin,

§

impl<T, const CAP: usize> UnwindSafe for FlattenObjects<T, CAP>
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> 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>,

§

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.