1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
//!
//! 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 [`Format`]s based on serde are included under feature flags.\
//!   More [`Source`]s and [`Format`]s 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
//!
//! * `std` - adds implementation of [`std::error::Error`] trait for error types.
//!   Enabled by default.
//! * `sync` - makes most types [`MaybeSend`] and some [`MaybeSync`]. Adds requirements for traits implementations to be [`MaybeSend`] and [`MaybeSync`] where needed.
//!   Enabled by default.
//!
//! ## 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
//!
//! * `futures-spawn` - adds [`Spawn`] implementation for [`futures_task::Spawn`](aka [`futures::task::Spawn`]) allowing to use compatible spawners to drive loading tasks to completion.
//! * `wasm-bindgen-spawn` - adds [`Spawn`] implementations that uses [`wasm_bindgen_futures::spawn_local`] to drive loadin tasks. Usable only on `wasm32` target.
//! * `tokio-spawn` - adds [`Spawn`] implementation for [`goods::Tokio`]([`tokio::runtime::Handle`] wrapper) allowing tokio to drive loading tasks. [`ReqwestSource`] requires [`tokio`] runtime.
//!
//! [`alloc`]: https://doc.rust-lang.org/alloc/index.html
//! [`HttpSource`]: ./struct.HttpSource.html
//! [`serde::de::DeserializeOwned`]: https://docs.rs/serde/1/serde/de/trait.DeserializeOwned.html
//! [`std::error::Error`]: https://doc.rust-lang.org/std/error/trait.Error.html
//! [`MaybeSend`]: https://doc.rust-lang.org/std/marker/trait.MaybeSend.html
//! [`MaybeSync`]: https://doc.rust-lang.org/std/marker/trait.MaybeSync.html
//! [`FileSource`]: ./struct.FileSource.html
//! [`Source`]: ./trait.Source.html
//! [`Source::read`]: ./trait.Source.html#tymethod.read
//! [`ReqwestSource`]: ./struct.ReqwestSource.html
//! [`FetchSource`]: https://docs.rs/goods/latest/wasm32-unknown-unknown/goods/struct.FetchSource.html
//! [`tokio`]: https://docs.rs/tokio
//! [`reqwest`]: https://docs.rs/reqwest
//! [`Format`]: ./trait.Format.html
//! [`JsonFormat`]: ./struct.JsonFormat.html
//! [`YamlFormat`]: ./struct.YamlFormat.html
//! [`RonFormat`]: ./struct.RonFormat.html
//! [`Spawn`]: ./trait.Spawn.html
//! [`futures_task::Spawn`]: https://docs.rs/futures-task/0.3/futures_task/trait.Spawn.html
//! [`futures::task::Spawn`]: https://docs.rs/futures/0.3/futures/task/trait.Spawn.html
//! [`wasm_bindgen_futures::spawn_local`]: https://docs.rs/wasm-bindgen-futures/0.4/wasm_bindgen_futures/fn.spawn_local.html
//! [`goods::Tokio`]: ./src/spawn.rs#L21
//! [`tokio::runtime::Handle`]: https://docs.rs/tokio/0.2/tokio/runtime/struct.Handle.html

#![cfg_attr(all(doc, feature = "unstable-doc"), feature(doc_cfg))]
#![doc(
    html_logo_url = "https://raw.githubusercontent.com/zakarumych/goods/master/logo/goods.logo.png"
)]

extern crate alloc;

mod asset;
mod bytes;
mod cache;
mod format;
mod handle;
mod key;
mod process;
mod registry;
mod source;

pub use self::{asset::*, cache::*, format::*, handle::*, key::*, registry::*, source::*};