goods
Easy-to-use asset manager for many environments.
Easy-to-use asset manager for many environments.
Goals
This crate is written with following goals in mind:
-
Batteries included.
Crate comes with variety of simple data sources likeFileSourceandHttpSource. FewFormats based on serde are included under feature flags.
MoreSources andFormats can be added. -
Extensibility.
MultipleFormattraits can be implemented for any asset type, including foreign asset types.
For exampleJsonFormat,YamlFormatandRonFormat(bundled in the crate) implementFormattrait for any asset type which intermediate representation implementsserde::de::DeserializeOwned. -
Supporting WebAssembly.
All mandatory dependencies are WASM-compatible and no threading is required for asset loading to work. -
Working with asynchronous data sources.
All data sources must implementSourcetrait.Source::readmethod returns future that will be driven to completion by the bound executor - seeSpawn. -
no_std
Butallocis required. -
Fast compilation.
build aftercargo cleantakes ~3s.
Non-Goals
This crate is not aimed to support every possible feature. Here's list of some of those features:
- Hot-reloading
Currently there are no plans to support hot-reloading.
Features
All out-of-the-box functionality exept core traits and types must be enabled with features.
General
std- adds implementation ofstd::error::Errortrait for error types. Enabled by default.
Sources
fs(enablesstd) - addsFileSource- aSourceimplementation that loads asset bytes from file-system.reqwest- addsReqwestSource- aSourceimplementation that loads asset bytes from URLs usingreqwest. Using this source requires spawner to spawn tasks withtokio. Otherwisereqwestinterals will panic.fetch- addsFetchSource- aSourceimplementation that uses browser's Fetch API to load assets data.data-url- adds [DataUrlSource] - aSourceimplementation that reads data embeded directly to url.
Formats
json-format- addsJsonFormat-Formatimplementation that treats asset bytes as JSON document and deserializes asset representation via serdeyaml-format- addsYamlFormat-Formatimplementation that treats asset bytes as YAML document and deserializes asset representation via serderon-format- addsRonFormat-Formatimplementation that treats asset bytes as RON document and deserializes asset representation via serde
Spawners
futures-spawn- addsSpawnimplementation forfutures_task::Spawn(akafutures::task::Spawn) allowing to use compatible spawners to drive loading tasks to completion.wasm-bindgen-spawn- addsSpawnimplementations that useswasm_bindgen_futures::spawn_localto drive loadin tasks. Usable only onwasm32target.tokio-spawn- addsSpawnimplementation forgoods::Tokio(tokio::runtime::Handlewrapper) allowing tokio to drive loading tasks.ReqwestSourcerequirestokioruntime.
Examples
There are few simple examples provided to learn how use this crate.
fs examlple
Shows how to build registry with FileSource and load simple assets from it.
reqwest example
Async example that loads assets using HTTP protocol with tokio and reqwest crates.
fetch example
Shows how to load assets in browser using Fetch API.
This example can be built using build-wasm32.sh or build-wasm32.bat in examples directory.
wasm-bindgen (compatible version) and wasm-opt must be in PATH
Then open http://localhost:8000/fetch in your favorite browser. Loaded assets must be shown on the page. Otherwise see for errors in log.
License
This repository is 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 Licensing
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.