1 unstable release

0.1.0 Feb 1, 2021

#1935 in Encoding

MIT/Apache

3KB

goods

Easy-to-use asset manager for many environments.

crates docs actions MIT/Apache loc

Easy-to-use asset manager for many environments.

Goals

This crate is written with following goals in mind:

  • Batteries included.
    Extension crates provide variety of useful data sources like FileSource and ReqwestSource. Serde based Formats are provided by goods-json, goods-yaml and goods-ron.

  • Extensibility.
    Multiple Format traits can be implemented for any asset type, including foreign asset types.
    For example JsonFormat, YamlFormat and RonFormat implement Format trait for any asset type which intermediate representation implements serde::de::DeserializeOwned.

  • Supporting WebAssembly.
    This crate and some of the extension crates are WASM-compatible and no threading is required for asset loading to work. Types and traits prefixed with Local remote Send and Sync from requirements and bounds. They can be used in single-threaded environment. Added specifically for WASM where !Send and !Sync types are common.

  • Working with asynchronous data sources.
    Raw data sources implement Source trait. Source::read method returns future that will be driven to completion by polling handle to asset.

  • Fast compilation.
    core crate (goods) build after cargo clean takes ~1s.

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 lives in their own goods-* crates.

Sources

Formats

  • goods-json - provides JsonFormat - treats raw bytes as JSON document and deserializes asset representation via serde
  • goods-yaml - provides YamlFormat - treats raw bytes as YAML document and deserializes asset representation via serde
  • goods-ron - provides RonFormat - treats raw bytes as RON document and deserializes asset representation via serde

Examples

There are few simple examples provided to learn how use this crate.

fs examlple

Shows how to build registry with DataUrlSource and load simple assets from it.

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) must be in PATH

cd examples
build-wasm32 fetch
python3 server.py

Then open http://localhost:8000/fetch.html 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

~1.6–2.2MB
~38K SLoC