pub struct Resources { /* private fields */ }Expand description
Container for engine resources.
Resources are stored by type and can be accessed through typed getters. Each resource type can only have one instance.
§Example
use astrelis::resource::Resources;
struct GameConfig {
title: String,
max_fps: u32,
}
let mut resources = Resources::new();
resources.insert(GameConfig {
title: "My Game".to_string(),
max_fps: 60,
});
let config = resources.get::<GameConfig>().unwrap();
assert_eq!(config.title, "My Game");Implementations§
Source§impl Resources
impl Resources
Sourcepub fn insert<R: Resource>(&mut self, resource: R) -> Option<R>
pub fn insert<R: Resource>(&mut self, resource: R) -> Option<R>
Insert a resource, replacing any existing resource of the same type.
Returns the previous resource if one existed.
Sourcepub fn get_mut<R: Resource>(&mut self) -> Option<&mut R>
pub fn get_mut<R: Resource>(&mut self) -> Option<&mut R>
Get a mutable reference to a resource.
Sourcepub fn get_or_insert_with<R: Resource>(
&mut self,
f: impl FnOnce() -> R,
) -> &mut R
pub fn get_or_insert_with<R: Resource>( &mut self, f: impl FnOnce() -> R, ) -> &mut R
Get or insert a resource with a default value.
Sourcepub fn get_or_default<R: Resource + Default>(&mut self) -> &mut R
pub fn get_or_default<R: Resource + Default>(&mut self) -> &mut R
Get or insert a resource with its default value.
Sourcepub fn type_names(&self) -> impl Iterator<Item = &'static str> + '_
pub fn type_names(&self) -> impl Iterator<Item = &'static str> + '_
List all resource type names (for debugging).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Resources
impl !RefUnwindSafe for Resources
impl Send for Resources
impl Sync for Resources
impl Unpin for Resources
impl UnsafeUnpin for Resources
impl !UnwindSafe for Resources
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more