Module assets_manager::asset

source ·
Expand description

Values loadable from a cache.

§Asset kinds

In assets_manager, assets are stored in an AssetCache, and are usually loaded from a Source, a file system abstraction. Most of the I/O with the source is handled by assets_manager, so you can focus on the rest.

This crate defines several kinds of assets, that have different use cases:

  • The most common, Assets, that are loaded from a single file. An Asset gives a way to get a Rust value from raw bytes. This is nothing more than sugar on top of Compound.
  • Compound are created by loading other assets and composing them. They can also read sources directly.
  • Storable is the widest category: everything 'static type can fit in it. Values of types that implement Storable can be inserted in a cache, but provide no way to construct them.

Additionnally, DirLoadable assets can be loaded by directory, eventually recursively. All Asset types implement this trait out of the box, but it can be extended to work with any Compound, though it requires a custom definition.

§Hot-reloading

Each asset is reloading when any file or directory it reads is modified, or when a asset it depends on is reloaded itself.

Additionally, one can explicitly disable hot-reloading for a type.

Note that hot-reloading is not atomic: if asset A depends on B, you can observe a state where B is reloaded but A is not reloaded yet. Additionally, if A fails to reload, the inconsistent state is kept as is.

Structs§

  • Bmpbmp
    An asset to load BMP images.
  • Flacflac
    Load FLAC sounds
  • Gltfgltf
    Loads glTF 3D assets.
  • Jpegjpeg
    An asset to load JPEG images.
  • Jsonjson
    Loads a value from a RON file.
  • Mp3mp3
    Load MP3 sounds
  • Pngpng
    An asset to load PNG images.
  • Ronron
    Loads a value from a JSON file.
  • Tomltoml
    Loads a value from a TOML file.
  • Vorbisvorbis
    Load Vorbis sounds
  • Wavwav
    Load WAV sounds
  • Webpwebp
    An asset to load WebP images.
  • Yamlyaml
    Loads a value from a YAML file.

Traits§

  • An asset is a type loadable from raw bytes.
  • An asset type that can load other kinds of assets.
  • Assets that are loadable from directories
  • Mark a type as not being hot-reloaded.
  • Trait marker to store values in a cache.