#assets #async #wasm #web #no_std

no-std goods

Asset manager for good assets

9 releases (5 breaking)

new 0.6.0 Oct 18, 2020
0.5.3 Jun 29, 2020
0.4.1 May 18, 2020
0.3.0 May 14, 2020
0.1.0 May 12, 2020

#104 in WebAssembly

44 downloads per month

MIT/Apache

165KB
1.5K SLoC

goods

Easy-to-use asset manager for many environments.

crates docs Actions License License

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 like FileSource and HttpSource. Few Formats based on serde are included under feature flags.
    More Sources and Formats can be added.

  • Extensibility.
    Multiple Format traits can be implemented for any asset type, including foreign asset types.
    For example JsonFormat, YamlFormat and RonFormat (bundled in the crate) implement Format trait for any asset type which intermediate representation implements serde::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 implement Source trait. Source::read method returns future that will be driven to completion by the bound executor - see Spawn.

  • no_std
    But alloc is required.

  • Fast compilation.
    build after cargo clean takes ~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 of std::error::Error trait for error types. Enabled by default.

Sources

  • fs (enables std) - adds FileSource - a Source implementation that loads asset bytes from file-system.
  • reqwest - adds ReqwestSource - a Source implementation that loads asset bytes from URLs using reqwest. Using this source requires spawner to spawn tasks with tokio. Otherwise reqwest interals will panic.
  • fetch - adds FetchSource - a Source implementation that uses browser's Fetch API to load assets data.
  • data-url - adds [DataUrlSource] - a Source implementation that reads data embeded directly to url.

Formats

  • json-format - adds JsonFormat - Format implementation that treats asset bytes as JSON document and deserializes asset representation via serde
  • yaml-format - adds YamlFormat - Format implementation that treats asset bytes as YAML document and deserializes asset representation via serde
  • ron-format - adds RonFormat - Format implementation that treats asset bytes as RON document and deserializes asset representation via serde

Spawners

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

cd examples
build-wasm32 fetch --features std,fetch,json-format,yaml-format,wasm-bindgen-spawn
python3 server.py

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

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.

Dependencies

~0.5–6.5MB
~143K SLoC