Assets

Struct Assets 

Source
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

Source

pub fn new() -> Self

Creates new instance of Assets container

Source

pub fn import(&mut self, path_str: &str) -> Id<Resource>

Imports an asset file by its path and returns Id of the Resource

Source

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");
}
Source

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

Source

pub fn store<T>(&mut self, asset: T) -> Id<T>
where Self: AssetMapGetter<T>,

Stores an asset and returns Id of it

Source

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

Source

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

Source

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

Source

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

Source

pub fn iter<T>(&mut self) -> Iter<'_, Id<T>, T>
where Self: AssetMapGetter<T>,

Returns iterator over assets by its type

Source

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

Source§

fn map(&self) -> &HashMap<Id<Animation>, Animation>

Returns HashMap reference for selected asset type
Source§

fn map_mut(&mut self) -> &mut HashMap<Id<Animation>, Animation>

Returns mutable HashMap reference for selected asset type
Source§

impl AssetMapGetter<Mesh> for Assets

Source§

fn map(&self) -> &HashMap<Id<Mesh>, Mesh>

Returns HashMap reference for selected asset type
Source§

fn map_mut(&mut self) -> &mut HashMap<Id<Mesh>, Mesh>

Returns mutable HashMap reference for selected asset type
Source§

impl AssetMapGetter<Resource> for Assets

Source§

fn map(&self) -> &HashMap<Id<Resource>, Resource>

Returns HashMap reference for selected asset type
Source§

fn map_mut(&mut self) -> &mut HashMap<Id<Resource>, Resource>

Returns mutable HashMap reference for selected asset type
Source§

impl AssetMapGetter<Shader> for Assets

Source§

fn map(&self) -> &HashMap<Id<Shader>, Shader>

Returns HashMap reference for selected asset type
Source§

fn map_mut(&mut self) -> &mut HashMap<Id<Shader>, Shader>

Returns mutable HashMap reference for selected asset type
Source§

impl AssetMapGetter<Skin> for Assets

Source§

fn map(&self) -> &HashMap<Id<Skin>, Skin>

Returns HashMap reference for selected asset type
Source§

fn map_mut(&mut self) -> &mut HashMap<Id<Skin>, Skin>

Returns mutable HashMap reference for selected asset type
Source§

impl AssetMapGetter<Texture> for Assets

Source§

fn map(&self) -> &HashMap<Id<Texture>, Texture>

Returns HashMap reference for selected asset type
Source§

fn map_mut(&mut self) -> &mut HashMap<Id<Texture>, Texture>

Returns mutable HashMap reference for selected asset type
Source§

impl Default for Assets

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for Assets

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Assets

Source§

impl Sync for Assets

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> IntoService for T
where T: Send + Sync + 'static,

Source§

fn service(self) -> Service<Self>

Constructs wrapped service
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Component for T
where T: Send + Sync + 'static,

Source§

impl<T> SystemContext for T
where T: Default + Send + Sync + 'static,