Skip to main content

ResourceRegistry

Struct ResourceRegistry 

Source
pub struct ResourceRegistry { /* private fields */ }

Implementations§

Source§

impl ResourceRegistry

Source

pub const fn new() -> Self

Source

pub fn insert<T: 'static>(&mut self, val: T)

Move val into the registry, keyed by its TypeId.

Inserted resources are dropped in reverse insertion order when the registry itself is dropped, matching Rust’s standard field/local destruction order.

§Alignment

T must have align_of::<T>() <= 8. AlignedStorage guarantees an 8-byte-aligned base; types with stricter alignment requirements cannot be stored safely and will cause a panic at insertion time.

§Panics

Panics if a resource of the same TypeId has already been inserted, if the registry is full (more than MAX_RESOURCES entries or STORAGE_SIZE bytes used), or if align_of::<T>() > 8.

Source

pub fn get_ptr<T: 'static>(&self) -> Option<*mut T>

Look up a resource by type, returning a raw pointer.

§Safety contract for callers

The returned pointer is valid for the lifetime of the registry. Creating a &mut T from it is safe provided:

  • Each concrete type is registered at most once (enforced by insert).
  • No two live &mut references alias the same entry.
  • Dispatch is single-threaded (one shim runs at a time).

Trait Implementations§

Source§

impl Default for ResourceRegistry

Source§

fn default() -> Self

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

impl Drop for ResourceRegistry

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

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.