Struct assets_manager::LocalAssetCache

source ·
pub struct LocalAssetCache<S = FileSystem> { /* private fields */ }
Expand description

Single-threaded version of AssetCache.

This type is not thread-safe, but is cheaper if you don’t need synchronization. It still requires stored assets to be thread-safe.

This cache does not support hot-reloading.

Implementations§

source§

impl LocalAssetCache

source

pub fn new<P: AsRef<Path>>(path: P) -> Result<Self>

Creates a new LocalAssetCache that reads assets from the given directory.

source§

impl<S> LocalAssetCache<S>

source

pub fn with_source(source: S) -> Self

Creates a new LocalAssetCache with the given source.

source§

impl<S: Source> LocalAssetCache<S>

source

pub fn get_cached<T: Storable>(&self, id: &str) -> Option<&Handle<T>>

Gets a value from the cache.

See AnyCache::get_cached for more details.

source

pub fn get_or_insert<T: Storable>(&self, id: &str, default: T) -> &Handle<T>

Gets a value from the cache or inserts one.

See AnyCache::get_or_insert for more details.

source

pub fn contains<T: Storable>(&self, id: &str) -> bool

Returns true if the cache contains the specified asset.

See AnyCache::contains for more details.

source

pub fn load<T: Compound>(&self, id: &str) -> Result<&Handle<T>, Error>

Loads an asset.

See AnyCache::load for more details.

source

pub fn load_expect<T: Compound>(&self, id: &str) -> &Handle<T>

Loads an asset and panic if an error happens.

See AnyCache::load_expect for more details.

source

pub fn load_dir<T: DirLoadable>( &self, id: &str ) -> Result<&Handle<Directory<T>>, Error>

Loads all assets of a given type from a directory.

See AnyCache::load_dir for more details.

source

pub fn load_rec_dir<T: DirLoadable>( &self, id: &str ) -> Result<&Handle<RecursiveDirectory<T>>, Error>

Loads all assets of a given type from a directory.

See AnyCache::load_dir for more details.

source

pub fn load_owned<T: Compound>(&self, id: &str) -> Result<T, Error>

Loads an owned version of an asset.

See AnyCache::load_owned for more details.

source

pub fn as_any_cache(&self) -> AnyCache<'_>

Converts to an AnyCache.

source§

impl<S> LocalAssetCache<S>

source

pub fn remove<T: Storable>(&mut self, id: &str) -> bool

Removes an asset from the cache, and returns whether it was present in the cache.

Note that you need a mutable reference to the cache, so you cannot have any Handle, AssetReadGuard, etc when you call this function.

source

pub fn take<T: Storable>(&mut self, id: &str) -> Option<T>

Takes ownership on a cached asset.

The corresponding asset is removed from the cache.

source

pub fn clear(&mut self)

Clears the cache.

Removes all cached assets and directories.

Trait Implementations§

source§

impl<'a, S: Source> AsAnyCache<'a> for &'a LocalAssetCache<S>

source§

fn as_any_cache(&self) -> AnyCache<'a>

Converts this type to an AnyCache.
source§

impl<S> Debug for LocalAssetCache<S>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<S> Default for LocalAssetCache<S>
where S: Source + Default,

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<S = FileSystem> !Freeze for LocalAssetCache<S>

§

impl<S = FileSystem> !RefUnwindSafe for LocalAssetCache<S>

§

impl<S> Send for LocalAssetCache<S>
where S: Send,

§

impl<S = FileSystem> !Sync for LocalAssetCache<S>

§

impl<S> Unpin for LocalAssetCache<S>
where S: Unpin,

§

impl<S = FileSystem> !UnwindSafe for LocalAssetCache<S>

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<S> FromSample<S> for S

source§

fn from_sample_(s: S) -> S

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, U> ToSample<U> for T
where U: FromSample<T>,

source§

fn to_sample_(self) -> U

source§

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

§

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>,

§

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<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,