Struct StrongRegistry

Source
pub struct StrongRegistry<H, T> { /* private fields */ }
Expand description

The same as Registry<T>, but with strongly-typed handles to prevent handles from being shared across multiple registries.

The handle type must implement the StrongHandle trait.

Implementations§

Source§

impl<H, T> StrongRegistry<H, T>
where H: StrongHandle,

Source

pub fn new() -> Self

Creates a new strong registry.

Source

pub fn with_capacity(size: usize) -> Self

Creates a new strong registry with the given capacity.

Source

pub fn is_empty(&self) -> bool

Checks if the registry is empty.

Source

pub fn len(&self) -> usize

Returns the number of elements owned by the strong registry.

Source

pub fn register(&self, value: T) -> H

Registers a new value in the arena, returning a handle to that value.

Source

pub fn register_extend<I>(&self, iterable: I) -> (H, H)
where I: IntoIterator<Item = T>,

Registers the contents of an iterator in the registry.

Returns a numeric range of handles [a, b), where a is the handle of the first element inserted and b is the handle after the last element inserted.

Source

pub fn reserve(&self, additional: usize)

Ensures there is enough continuous space for at least additional values.

Source

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

Converts the StrongRegistry<T> into a Vec<T>.

Items will maintain their handle as their vector index.

Source

pub fn iter( &self, ) -> impl Iterator<Item = Result<ElementRef<'_, T>, BorrowError>>

Returns an iterator that provides immutable access to all elements in the registry, in order of registration.

Source

pub fn iter_mut( &mut self, ) -> impl Iterator<Item = Result<ElementRefMut<'_, T>, BorrowError>>

Returns an iterator that provides mutable access to all elements in the registry, in order of registration.

Source

pub fn get_unchecked(&self, handle: H) -> ElementRef<'_, T>

Returns a reference to a value previously registered in the registry.

Panics if there is a borrow error.

Source

pub fn get(&self, handle: H) -> Result<ElementRef<'_, T>, BorrowError>

Tries to get a reference to a value previously registered in the registry.

Source

pub fn get_mut_unchecked(&self, handle: H) -> ElementRefMut<'_, T>

Returns a mutable reference to a value previously registered in the registry.

Panics if there is a borrow error.

Source

pub fn get_mut(&self, handle: H) -> Result<ElementRefMut<'_, T>, BorrowError>

Tries to get a mutable reference to a value previously registered in the registry.

Source

pub fn safe_to_drop(&mut self) -> bool

Checks if the registry is safe to drop.

A registry is safe to drop if all elements are not borrowed. This check is not thread safe.

Trait Implementations§

Source§

impl<H: Default, T: Default> Default for StrongRegistry<H, T>

Source§

fn default() -> StrongRegistry<H, T>

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

Auto Trait Implementations§

§

impl<H, T> !Freeze for StrongRegistry<H, T>

§

impl<H, T> !RefUnwindSafe for StrongRegistry<H, T>

§

impl<H, T> Send for StrongRegistry<H, T>
where H: Send, T: Send,

§

impl<H, T> !Sync for StrongRegistry<H, T>

§

impl<H, T> Unpin for StrongRegistry<H, T>
where H: Unpin, T: Unpin,

§

impl<H, T> !UnwindSafe for StrongRegistry<H, T>

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.