Struct zone_alloc::registry::Registry
source · pub struct Registry<T> { /* private fields */ }Expand description
A container that can be used for registering values of a given type and retrieving references by handle.
A Registry is a centralized data source that values can be inserted into. After insertion,
the registry returns a Handle, which will refer to the same value for the lifetime of the
registry.
A single value can be moved into the registry using Registry::register, and multiple values
can be moved in using Registry::register_extend.
Internally, a registry uses an Arena for allocating values, which guarantees references are
valid for the lifetime of the arena. A Registry adds the additional guarantees that all
handles will refer to a single value in the underlying arena for the lifetime of the registry.
Implementations§
source§impl<T> Registry<T>
impl<T> Registry<T>
sourcepub fn with_capacity(size: usize) -> Self
pub fn with_capacity(size: usize) -> Self
Creates a new registry with the given capacity.
sourcepub fn register(&self, value: T) -> Handle
pub fn register(&self, value: T) -> Handle
Registers a new value in the arena, returning a handle to that value.
sourcepub fn register_extend<I>(&self, iterable: I) -> (Handle, Handle)where
I: IntoIterator<Item = T>,
pub fn register_extend<I>(&self, iterable: I) -> (Handle, Handle)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.
sourcepub fn reserve(&self, additional: usize)
pub fn reserve(&self, additional: usize)
Ensures there is enough continuous space for at least additional values.
sourcepub fn into_vec(self) -> Vec<T>
pub fn into_vec(self) -> Vec<T>
Converts the Registry<T> into a Vec<T>.
Items will maintain their handle as their vector index.
sourcepub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
Returns an iterator that provides mutable access to all elements in the registry, in order of registration.
Registries only allow mutable iteration because the entire registry must be borrowed for the duration of the iteration. The mutable borrow to call this method allows Rust’s borrow checker to enforce this rule.