Assets-manager
Conveniently load, cache, and reload external resources.
This crate's main focuses are:
- Pleasant to use: Simple and well-documented high-level API
- Light: Pay for what you take, no dependency bloat
- Concurrency: Essential for computing-heavy uses such as games
This crate follow semver convention and supports rustc 1.42.0 and higher. Changing this is considered a breaking change.
Note: this crate is still under developpement and breaking changes will happen in the future, but use, feedbacks and requests are welcome and encouraged.
Example
Suppose that you have a file assets/common/position.ron
containing this:
Point(
x: 5,
y: -6,
)
Then you can load it this way (with feature ron
enabled):
use ;
use Deserialize;
// The struct you want to load
// Specify how you want the structure to be loaded
// Create a new cache to load assets under the "./assets" folder
let cache = new;
// Get a lock on the asset
// This will load the file `./assets/common/position.ron`
let asset_lock = cache.?;
// 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!;
assert_eq!;
// Loading the same asset retreives it from the cache
let other_lock = cache.load?;
assert!;
Hot-reloading is also very easy to use:
let cache = new;
let asset_lock = cache.?;
loop
Features
Current features:
- Convenient load of external files
- Cache loaded assets
- Hot-reloading
- Built-in support of most common data formats with serde
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.