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<S> LocalAssetCache<S>
impl<S> LocalAssetCache<S>
sourcepub fn with_source(source: S) -> Self
pub fn with_source(source: S) -> Self
Creates a new LocalAssetCache
with the given source.
source§impl<S: Source> LocalAssetCache<S>
impl<S: Source> LocalAssetCache<S>
sourcepub fn get_cached<T: Storable>(&self, id: &str) -> Option<&Handle<T>>
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.
sourcepub fn get_or_insert<T: Storable>(&self, id: &str, default: T) -> &Handle<T>
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.
sourcepub fn contains<T: Storable>(&self, id: &str) -> bool
pub fn contains<T: Storable>(&self, id: &str) -> bool
Returns true
if the cache contains the specified asset.
See AnyCache::contains
for more details.
sourcepub fn load<T: Compound>(&self, id: &str) -> Result<&Handle<T>, Error>
pub fn load<T: Compound>(&self, id: &str) -> Result<&Handle<T>, Error>
Loads an asset.
See AnyCache::load
for more details.
sourcepub fn load_expect<T: Compound>(&self, id: &str) -> &Handle<T>
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.
sourcepub fn load_dir<T: DirLoadable>(
&self,
id: &str
) -> Result<&Handle<Directory<T>>, Error>
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.
sourcepub fn load_rec_dir<T: DirLoadable>(
&self,
id: &str
) -> Result<&Handle<RecursiveDirectory<T>>, Error>
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.
sourcepub fn load_owned<T: Compound>(&self, id: &str) -> Result<T, Error>
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.
sourcepub fn as_any_cache(&self) -> AnyCache<'_>
pub fn as_any_cache(&self) -> AnyCache<'_>
Converts to an AnyCache
.
source§impl<S> LocalAssetCache<S>
impl<S> LocalAssetCache<S>
sourcepub fn remove<T: Storable>(&mut self, id: &str) -> bool
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.
Trait Implementations§
source§impl<'a, S: Source> AsAnyCache<'a> for &'a LocalAssetCache<S>
impl<'a, S: Source> AsAnyCache<'a> for &'a LocalAssetCache<S>
source§fn as_any_cache(&self) -> AnyCache<'a>
fn as_any_cache(&self) -> AnyCache<'a>
AnyCache
.