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 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 can be enabled with features.

General

Sources

  • fs (enables std) - adds FileSource - Source implementation that loads asset bytes from file-system.
  • reqwest - adds ReqwestSource - 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 that uses browser's Fetch API to load assets data. Conflicts with sync feature.

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

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 Cache to load new assets.

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 Cache::process call.

Registry

Collection of registered sources. Used by Cache to load new assets.

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 Format implemetations.

AssetDefaultFormat

Default format for given asset type. Allows calling Cache::load and make it use default format value for loading. Has no effect otherwise.

AutoLocalSource
Format

Format trait interprets raw bytes as an asset. It may also use context for asset instance creation and Cache to load compound assets.

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 LocalCache to load compound assets.

LocalSource

Asset data source.

SimpleAsset

Shortcut for implementing Asset when asset is produced directly by Format and no building is required.

SimpleFormat
Source

Asset data source.

SyncAsset

Shortcut for implementing Asset when asset building is synchronous.