Skip to main content

ResourceProvider

Trait ResourceProvider 

Source
pub unsafe trait ResourceProvider<T: ?Sized + 'static, Tag: 'static = DefaultResourceTag> {
    const ID: ResourceId;

    // Required method
    unsafe fn get(resources: *mut Self) -> *mut T;
}
Expand description

Provides one typed resource from an application-owned container.

Tag distinguishes multiple fields with the same T. Applications should normally use crate::resources!, which generates these implementations together with the resource container.

§Safety

Every implementation that may return overlapping memory must use the same ID. A non-null, aligned pointer returned by get must point to a live T inside Self, remain valid while the container is exclusively borrowed, and must not be used to move the container field. Null or misaligned pointers are reported as crate::FetchError::InvalidPointer.

Required Associated Constants§

Source

const ID: ResourceId

Identity used to detect overlapping shared and exclusive access.

Required Methods§

Source

unsafe fn get(resources: *mut Self) -> *mut T

Returns a pointer to the provided resource.

§Safety

resources must point to a live, properly aligned Self that is exclusively borrowed for the entire lifetime of any value derived from the returned pointer.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§