pub struct ResourceRegistry { /* private fields */ }Implementations§
Source§impl ResourceRegistry
impl ResourceRegistry
pub const fn new() -> Self
Sourcepub fn insert<T: 'static>(&mut self, val: T)
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.
Sourcepub fn get_ptr<T: 'static>(&self) -> Option<*mut T>
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
&mutreferences alias the same entry. - Dispatch is single-threaded (one shim runs at a time).
Trait Implementations§
Source§impl Default for ResourceRegistry
impl Default for ResourceRegistry
Source§impl Drop for ResourceRegistry
impl Drop for ResourceRegistry
Auto Trait Implementations§
impl !Freeze for ResourceRegistry
impl !RefUnwindSafe for ResourceRegistry
impl Send for ResourceRegistry
impl !Sync for ResourceRegistry
impl Unpin for ResourceRegistry
impl UnsafeUnpin for ResourceRegistry
impl UnwindSafe for ResourceRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more