1 unstable release
0.1.0 | Feb 1, 2021 |
---|
#10 in #asset-manager
4KB
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.
Extension crates provide variety of useful data sources likeFileSource
andReqwestSource
. Serde basedFormat
s are provided bygoods-json
,goods-yaml
andgoods-ron
. -
Extensibility.
MultipleFormat
traits can be implemented for any asset type, including foreign asset types.
For exampleJsonFormat
,YamlFormat
andRonFormat
implementFormat
trait for any asset type which intermediate representation implementsserde::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 withLocal
remoteSend
andSync
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 implementSource
trait.Source::read
method returns future that will be driven to completion by polling handle to asset. -
Fast compilation.
core crate (goods
) build aftercargo 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
goods-dataurl
- providesxDataUrlSource
- reads data embeded directly to url.goods-fs
- provides addsFileSource
- loads asset bytes from file-system.goods-reqwest
- providesReqwestSource
- loads asset bytes from URLs usingreqwest
.tokio
runtime should be used to poll futures in this case.goods-fetch
- providesFetchSource
- uses browser's Fetch API to load assets data.
Formats
goods-json
- providesJsonFormat
- treats raw bytes as JSON document and deserializes asset representation via serdegoods-yaml
- providesYamlFormat
- treats raw bytes as YAML document and deserializes asset representation via serdegoods-ron
- providesRonFormat
- 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
- 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.
Dependencies
~1.5MB
~22K SLoC