[−][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.
hot-reloading: Add hot-reloading
Additionnal loaders
bincode: Bincode deserializationcbor: CBOR deserializationjson: JSON deserializationmsgpack: MessagePack deserializationron: RON deserializationtoml: TOML deserializationyaml: YAML deserialization
Internal features
These features change inner data structures implementations.
parking_lot: Use parking_lot crate's synchronisation primitives
Example
If the file assets/common/position.ron contains this:
Point(
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 #[derive(Deserialize)] 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")?; assert!(asset_lock.ptr_eq(&other_lock));
Modules
| loader | Generic asset loading definition |
Structs
| AssetCache | The main structure of this crate, used to cache assets. |
| AssetRef | RAII guard used to keep a read lock on an asset and release it when dropped. |
| AssetRefLock | A lock on an asset. |
Enums
| AssetError | An error that occured when loading an asset. |
Traits
| Asset | An asset is a type loadable from a file. |