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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//! # wasset
//!
//! This crate allows for embedding external asset files (text, images, models) into WASM plugins. The assets are stored in the WASM module's custom data section. This allows for reading assets on the host using a `WassetParser`. The WASM module itself can reference its assets by macro-generated ID.
//!
//! `wasset` is meant to be a foundation for game asset systems. It differs from using `include_bytes!()` to include assets in the following ways:
//!
//! - The host can read a WASM module's assets without loading the WASM itself. This allows a game engine to preload or lazily load all assets, before instantiating the WASM modules.
//! - Separate WASM modules can reference and share assets by `WassetId`.
//! - Because assets are stored in a custom section, it's not necessary to load all assets into memory when instantiating the WASM module. This can conserve memory for WASM modules that include many assets.
//!
//! ---
//!
//! ## Usage
//!
//! `wasset` does not define an asset format - rather, it provides the means to load and store a user-specified asset type to WASM. Therefore, setting up `wasset` requires:
//!
//! - Defining an `AssetSchema` type that can be serialized and deserialized with `serde`
//! - Implementing `AssetEncoder` to determine how files are turned into assets
//! - Re-exporting the `wasset::include_assets::<A: AssetEncoder>(path)` macro with the appropriate asset encoder type
//!
//! [A complete example is available here.](/wasset_example/) Once the asset type and macro have been defined, they may be used from within WASM as follows:
//!
//! ```ignore
//! use wasset::*;
//! use wasset_example_macro::*;
//!
//! // Load all assets from the given folder. This is the
//! // macro defined for a specific `AssetEncoder`.
//! include_assets!("wasset_example/wasset_example_module/assets");
//!
//! /// Gets a list of all assets from this module.
//! pub fn list_all_assets() -> &'static [WassetId] {
//! &[
//! // The macro has defined these for us.
//! assets::SOME_BINARY,
//! assets::SOME_TEXT,
//! assets::submodule::MORE_TEXT
//! ]
//! }
//! ```
//!
//! Then, the asset data for this WASM plugin may be examined from the host:
//!
//! ```ignore
//! use wasset::*;
//! use wasset_example_schema::*;
//!
//! fn main() {
//! // Create a parser from the bytes of the WASM module.
//! let parser = WassetParser::<ExampleAsset>::parse(EXAMPLE_PLUGIN_WASM).unwrap();
//! for (id, asset) in &parser {
//! println!("{id:?} | {asset:?}");
//!
//! // Prints something like:
//! // WassetId(9ee64711-8e7e-4e40-a1bc-f13a1b4e5bdb) | Ok(Binary([97, 115, 106, 100]))
//! // WassetId(b230fb86-8bf6-49a0-94f9-624386204129) | Ok(Text("Even more!"))
//! // WassetId(ae189ff9-b0d4-48fc-b0e1-3093d53bff85) | Ok(Text("Hello world!"))
//! }
//! }
//! ```
//!
//! ## Optional features
//!
//! - **bytemuck** - implements the `Pod` and `Zeroable` attributes on relevant types.
//! - **encode** - allows for serializing a folder of assets into memory.
//! - **encode_macro** - exposes a generic macro that, when instantiated, will embed a folder of assets into a WASM module.
//! - **parse** - exposes the ability to read a WASM module's assets.
//! - **relative_path** - (requires nightly) makes the `encode_macro` use relative paths rather than paths from the project root.
pub use crate*;
pub use crate*;
use *;
use *;
use *;
use *;
use *;
use *;
/// Implements the ability to write assets from a directory.
/// Implements the ability to read assets from a WASM module.
/// Represents an asset type which may be stored and loaded from WASM.
/// A unique ID associated with an asset.
;
unsafe
unsafe
/// A list which describes the list of assets present in a WASM module.
/// Represents an error that occurred during asset processing.