Skip to main content

AssetServerCacheExt

Trait AssetServerCacheExt 

Source
pub trait AssetServerCacheExt {
    // Required method
    fn load_cached<A: Asset>(
        &self,
        manifest: &CacheManifest,
        config: &CacheConfig,
        key: &str,
    ) -> Result<Handle<A>, CacheError>;
}
Expand description

Extension trait that adds cache-aware loading to AssetServer.

§Example

use bevy_cache::AssetServerCacheExt;

fn setup(
    asset_server: Res<AssetServer>,
    manifest: Res<CacheManifest>,
    config: Res<CacheConfig>,
) {
    let handle: Handle<Image> = asset_server
        .load_cached(&manifest, &config, "scene_thumb")
        .unwrap_or_else(|_| regenerate_thumbnail(&asset_server));
}

Required Methods§

Source

fn load_cached<A: Asset>( &self, manifest: &CacheManifest, config: &CacheConfig, key: &str, ) -> Result<Handle<A>, CacheError>

Load a cached asset by key.

Returns Ok(Handle<A>) when the cache file is present, or CacheError::NotFound when there is no manifest entry or the file was deleted from disk.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl AssetServerCacheExt for AssetServer

Source§

fn load_cached<A: Asset>( &self, manifest: &CacheManifest, config: &CacheConfig, key: &str, ) -> Result<Handle<A>, CacheError>

Implementors§