pub trait Resource: Any + Send + Sync + 'static { }
Expand description
A resource is a data slot which lives in the World
can only be accessed
according to Rust’s typical borrowing model (one writer xor multiple
readers).
Implementations§
source§impl dyn Resource
impl dyn Resource
sourcepub fn downcast<T>(
self: Box<dyn Resource, Global>
) -> Result<Box<T, Global>, Box<dyn Resource, Global>>where
T: Resource,
pub fn downcast<T>( self: Box<dyn Resource, Global> ) -> Result<Box<T, Global>, Box<dyn Resource, Global>>where T: Resource,
Returns the boxed value if it is of type T
, or Err(Self)
if it
isn’t.
sourcepub unsafe fn downcast_unchecked<T>(
self: Box<dyn Resource, Global>
) -> Box<T, Global>where
T: Resource,
pub unsafe fn downcast_unchecked<T>( self: Box<dyn Resource, Global> ) -> Box<T, Global>where T: Resource,
Returns the boxed value, blindly assuming it to be of type T
.
Safety
If you are not absolutely certain of T
, you must not call this.
Using anything other than the correct type T
for this Resource
will result in UB.
sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: Resource,
pub fn downcast_ref<T>(&self) -> Option<&T>where T: Resource,
Returns some reference to the boxed value if it is of type T
, or
None
if it isn’t.
sourcepub unsafe fn downcast_ref_unchecked<T>(&self) -> &Twhere
T: Resource,
pub unsafe fn downcast_ref_unchecked<T>(&self) -> &Twhere T: Resource,
Returns a reference to the boxed value, blindly assuming it to be of
type T
.
Safety
If you are not absolutely certain of T
, you must not call this.
Using anything other than the correct type T
for this Resource
will result in UB.
sourcepub fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: Resource,
pub fn downcast_mut<T>(&mut self) -> Option<&mut T>where T: Resource,
Returns some mutable reference to the boxed value if it is of type T
,
or None
if it isn’t.
sourcepub unsafe fn downcast_mut_unchecked<T>(&mut self) -> &mut Twhere
T: Resource,
pub unsafe fn downcast_mut_unchecked<T>(&mut self) -> &mut Twhere T: Resource,
Returns a mutable reference to the boxed value, blindly assuming it to
be of type T
.
Safety
If you are not absolutely certain of T
, you must not call this.
Using anything other than the correct type T
for this Resource
will result in UB.