pub struct Assets { /* private fields */ }Expand description
Assets management service
Stored asset can be identified by its Id. The Id is being assigned to an asset, once
the asset is stored.
File operations performed by the service are being executed in separate threads, so no execution blocking happens. Due to some resources may contain several assets, they may not be loaded at the same time. Also bigger assets may take longer time to be loaded.
There is a way to aquire asset Id immediately without awaiting using Assets::register
method.
Implementations§
Source§impl Assets
impl Assets
Sourcepub fn register<T>(&mut self, name: &str) -> Id<T>where
Self: AssetMapGetter<T>,
pub fn register<T>(&mut self, name: &str) -> Id<T>where
Self: AssetMapGetter<T>,
Associates an asset name with Id and returns it
If name was already used, then no changes will be done and already associated Id will
be returned.
As it was said, names of assets loaded with Assets::import method can be predictable
in most cases. Using that prediction, developer can obtain an Id even before calling
the Assets::import method.
use dotrix_core::{
assets::Texture,
ecs::Mut,
services::Assets,
};
fn my_system(mut assets: Mut<Assets>) {
// get the id
let texture = assets.register::<Texture>("my_texture");
// import the texture
assets.import("/path/to/my_texture.png");
}Sourcepub fn store_as<T>(&mut self, asset: T, name: &str) -> Id<T>where
Self: AssetMapGetter<T>,
pub fn store_as<T>(&mut self, asset: T, name: &str) -> Id<T>where
Self: AssetMapGetter<T>,
Stores an asset under user defined name and returns Id of it
Sourcepub fn store<T>(&mut self, asset: T) -> Id<T>where
Self: AssetMapGetter<T>,
pub fn store<T>(&mut self, asset: T) -> Id<T>where
Self: AssetMapGetter<T>,
Stores an asset and returns Id of it
Sourcepub fn find<T>(&self, name: &str) -> Option<Id<T>>where
Self: AssetMapGetter<T>,
pub fn find<T>(&self, name: &str) -> Option<Id<T>>where
Self: AssetMapGetter<T>,
Searches for an asset by the name and return Id of it if the asset exists
Sourcepub fn get<T>(&self, handle: Id<T>) -> Option<&T>where
Self: AssetMapGetter<T>,
pub fn get<T>(&self, handle: Id<T>) -> Option<&T>where
Self: AssetMapGetter<T>,
Searches an asset by its Id and returns it by a reference if the asset exists
Sourcepub fn get_mut<T>(&mut self, handle: Id<T>) -> Option<&mut T>where
Self: AssetMapGetter<T>,
pub fn get_mut<T>(&mut self, handle: Id<T>) -> Option<&mut T>where
Self: AssetMapGetter<T>,
Searches an asset by its Id and returns it by a mutual reference if the asset exists
Sourcepub fn remove<T>(&mut self, handle: Id<T>) -> Option<T>where
Self: AssetMapGetter<T>,
pub fn remove<T>(&mut self, handle: Id<T>) -> Option<T>where
Self: AssetMapGetter<T>,
Removes an asset from the Service and returns it if the asset exists
Sourcepub fn iter<T>(&mut self) -> Iter<'_, Id<T>, T>where
Self: AssetMapGetter<T>,
pub fn iter<T>(&mut self) -> Iter<'_, Id<T>, T>where
Self: AssetMapGetter<T>,
Returns iterator over assets by its type
Sourcepub fn iter_mut<T>(&mut self) -> IterMut<'_, Id<T>, T>where
Self: AssetMapGetter<T>,
pub fn iter_mut<T>(&mut self) -> IterMut<'_, Id<T>, T>where
Self: AssetMapGetter<T>,
Returns mutable iterator over assets by its type
Trait Implementations§
Source§impl AssetMapGetter<Animation> for Assets
impl AssetMapGetter<Animation> for Assets
Source§impl AssetMapGetter<Mesh> for Assets
impl AssetMapGetter<Mesh> for Assets
Source§impl AssetMapGetter<Resource> for Assets
impl AssetMapGetter<Resource> for Assets
Source§impl AssetMapGetter<Shader> for Assets
impl AssetMapGetter<Shader> for Assets
Source§impl AssetMapGetter<Skin> for Assets
impl AssetMapGetter<Skin> for Assets
Source§impl AssetMapGetter<Texture> for Assets
impl AssetMapGetter<Texture> for Assets
impl Send for Assets
impl Sync for Assets
Auto Trait Implementations§
impl Freeze for Assets
impl !RefUnwindSafe for Assets
impl Unpin for Assets
impl !UnwindSafe for Assets
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
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>
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>
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