[][src]Crate assets_manager

Conveniently load, store and cache external resources.

It has multiple goals

  • Easy to use: Rusty API
  • Light: Pay for what you take, no dependencies bloat
  • Fast: Share your resources between threads without using expensive Arc::clone

Cargo features

No features are enabled by default.

Additionnal loaders

  • bincode: Bincode deserialization
  • cbor: CBOR deserialization
  • json: JSON deserialization
  • msgpack: MessagePack deserialization
  • ron: RON deserialization
  • toml: TOML deserialization
  • yaml: YAML deserialization

Internal features

These features change inner data structures implementations.

  • hashbrown: Use hashbrown crate's HashMap
  • parking_lot: Use parking_lot crate's synchronisation primitives


If the file assets/common/position.ron contains this:

    x: 5,
    y: -6,

Then you can load it this way (with feature ron enabled):

use assets_manager::{Asset, AssetCache, loader};
use serde::Deserialize;

// The struct you want to load
struct Point {
    x: i32,
    y: i32,

// Specify how you want the structure to be loaded
impl Asset for Point {
    // The extension of the files to look into
    const EXT: &'static str = "ron";

    // The serialization format
    type Loader = loader::RonLoader;

// Create a new cache to load assets under the "./assets" folder
let cache = AssetCache::new("assets");

// Get a lock on the asset
let asset_lock = cache.load::<Point>("common.position")?;

// Lock the asset for reading
// Any number of read locks can exist at the same time,
// but none can exist when the asset is reloaded
let point = asset_lock.read();

// The asset is now ready to be used
assert_eq!(point.x, 5);
assert_eq!(point.y, -6);

// Loading the same asset retreives it from the cache
let other_lock = cache.load("common.position")?;



Generic asset loading definition



The main structure of this crate, used to cache assets.


RAII guard used to keep a read lock on an asset and release it when dropped.


A lock on an asset.



An error that occured when loading an asset.



An asset is a type loadable from a file.


Specifies how an asset is loaded.