Crate goods[−][src]
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 likeFileSource
andHttpSource
. FewFormat
s based on serde are included under feature flags.
MoreSource
s andFormat
s can be added. -
Extensibility.
MultipleFormat
traits can be implemented for any asset type, including foreign asset types.
For exampleJsonFormat
,YamlFormat
andRonFormat
(bundled in the crate) implementFormat
trait 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 implementSource
trait.Source::read
method returns future that will be driven to completion by the bound executor - seeSpawn
. -
no_std
Butalloc
is required. -
Fast compilation.
build aftercargo 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 can be enabled with features.
General
std
- adds implementation ofstd::error::Error
trait for error types. Enabled by default.sync
- makes most typesMaybeSend
and someMaybeSync
. Adds requirements for traits implementations to beMaybeSend
andMaybeSync
where needed. Enabled by default.
Sources
fs
(enablesstd
) - addsFileSource
-Source
implementation that loads asset bytes from file-system.reqwest
- addsReqwestSource
-Source
implementation that loads asset bytes from URLs usingreqwest
. Using this source requires spawner to spawn tasks withtokio
. Otherwisereqwest
interals will panic.fetch
- addsFetchSource
that uses browser's Fetch API to load assets data. Conflicts withsync
feature.
Formats
json-format
- addsJsonFormat
-Format
implementation that treats asset bytes as JSON document and deserializes asset representation via serdeyaml-format
- addsYamlFormat
-Format
implementation that treats asset bytes as YAML document and deserializes asset representation via serderon-format
- addsRonFormat
-Format
implementation that treats asset bytes as RON document and deserializes asset representation via serde
Spawners
futures-spawn
- addsSpawn
implementation forfutures_task::Spawn
(akafutures::task::Spawn
) allowing to use compatible spawners to drive loading tasks to completion.wasm-bindgen-spawn
- addsSpawn
implementations that useswasm_bindgen_futures::spawn_local
to drive loadin tasks. Usable only onwasm32
target.tokio-spawn
- addsSpawn
implementation forgoods::Tokio
(tokio::runtime::Handle
wrapper) allowing tokio to drive loading tasks.ReqwestSource
requirestokio
runtime.
Structs
AssetNotFound | |
Cache | Asset cache. This type is main entry point for asset loading. Caches loaded assets and provokes loading work for new assets. |
Handle | |
LocalCache | Asset cache. This type is main entry point for asset loading. Caches loaded assets and provokes loading work for new assets. |
LocalHandle | |
LocalRegistry | Collection of registered sources.
Used by |
LocalRegistryBuilder | Builder for source registry. |
PassthroughFormat | |
PhantomContext | Dummy context for assets that doesn't require one.
Reduces overhead and allows producing asset faster
without waiting for next |
Registry | Collection of registered sources.
Used by |
RegistryBuilder | Builder for source registry. |
Traits
Asset | Loaded, processed and prepared asset.
This trait specifies how asset instances can be built from intermediate values
that are produced by |
AssetDefaultFormat | Default format for given asset type.
Allows calling |
AutoLocalSource | |
Format | Format trait interprets raw bytes as an asset.
It may also use context for asset instance creation
and |
Key | Compound trait that is implemented for any type that implements all bound traits. |
LocalFormat | Format trait interprets raw bytes as an asset.
It may also use context for asset instance creation
and |
LocalSource | Asset data source. |
SimpleAsset | Shortcut for implementing |
SimpleFormat | |
Source | Asset data source. |
SyncAsset | Shortcut for implementing |