Module source

Expand description

Bytes sources to load assets from.

This module contains the Source trait, which defines how files are read. The primary use of this trait is with [AssetCache] to provide flexible asset loading from different storage backends.

Built-in sources include:

  • FileSystem: Load from local filesystem
  • [Zip]: Load from ZIP archives
  • Tar: Load from TAR archives
  • [Embedded]: Load from assets embedded in the binary

§Hot-reloading

Hot-reloading enables assets to be automatically reloaded when their source files are modified. This functionality requires the Source implementation to support it. The built-in FileSystem source provides hot-reloading support out of the box.

§Platform-specific source selection

Since WebAssembly doesn’t have filesystem access, you can conditionally use different sources based on the target platform. For example, use filesystem on native platforms and embedded assets on WASM:

use assets_manager::{AssetCache, source};

#[cfg(not(target_arch = "wasm32"))]
let source = source::FileSystem::new("assets")?;

#[cfg(target_arch = "wasm32")]
let source = source::Embedded::from(source::embed!("assets"));

let cache = AssetCache::with_source(source);

Structs§

Empty
A Source that contains nothing.
FileSystem
A Source to load assets from a directory in the file system.
Tar
A [Source] to load assets from a tar archive.

Enums§

DirEntry
An entry in a source.
FileContent
The raw content of a file.
OwnedDirEntry
An owned version of a DirEntry

Traits§

Source
Bytes sources to load assets from.