Expand description
Asset loader.
§Asset and AssetField derive macros
Creates structures to act as two loading stages of asset and implement asset using those.
First stages must be deserializable with serde.
All fields with #[external] must implement AssetField<External>. Which has blanket impl for Asset implementors and some wrappers, like Option<A> and Arc<[A]> where A: Asset.
All fields with #[container] attribute must implement AssetField<Container>. It can be derived using derive(AssetField). They can in turn contain fields with #[external] and #[container] attributes. Also implemented for wrappers like Option<A> and Arc<[A]>.
All fields without special attributes of the target struct must implement DeserializeOwned.
All fields transiently with #[external] attribute will be replaced with id for first stage struct and AssetResults for second stage.
Second stages will have AssetResults fields in place of the assets.
§Example
/// Simple deserializable type. Included as-is into generated types for `#[derive(Asset)]` and #[derive(AssetField)].
#[derive(Clone, serde::Deserialize)]
struct Foo;
/// Trivial asset type.
#[derive(Clone, Asset)]
#[asset(name = "bar")]
struct Bar;
/// Asset field type. `AssetField<Container>` implementation is generated, but not `Asset` implementation.
/// Fields of types with `#[derive(AssetField)]` attribute are not replaced by uuids as external assets.
#[derive(Clone, AssetField)]
struct Baz;
/// Asset structure. Implements Asset trait using
/// two generated structures are intermediate phases.
#[derive(Clone, Asset)]
#[asset(name = "assetstruct")]
struct AssetStruct {
/// Deserializable types are inlined into asset as is.
foo: Foo,
/// `AssetField<External>` is implemented for all `Asset` implementors.
/// Deserialized as `AssetId` and loaded recursively.
#[asset(external)]
bar: Bar,
/// Container fields are deserialized similar to types that derive `Asset`.
/// If there is no external asset somewhere in hierarchy, decoded `Baz` is structurally equivalent to `Baz`.
#[asset(container)]
baz: Baz,
}Modules§
Structs§
- Asset
Handle - AssetId
- Type for unique asset identification. There are 2^64-1 valid values of this type that should be enough for now.
- Asset
Result - Asset
Result Poisoned - Error
- Loader
- Virtual storage for all available assets.
- Loader
Builder - Builder for
Loader. Allows configure asset loader with requiredSources. - Typed
Asset Id AssetIdaugmented with type information, specifying which asset type is referenced.
Enums§
- Container
- Decode
Error - Error type used by derive-macro.
- External
- Key
- Parse
Asset IdError
Traits§
- Asset
- An asset type that can be built from decoded representation.
- Asset
Build - Asset building trait.
Users should implement this trait for at least single choice of
B. But it is highly recommended to implement this trait for wide choices ofBfor improved composability. Because composite asset will implementAssetBuild<B>only for such typesBfor which all components implementAssetBuild<B>. - Asset
Field - This trait is used by code generated by
AssetandAssetFieldderive macros. Types must implementAssetFieldin order to be usable as field types in structures that deriveAssetorAssetField. - Asset
Field Build - This trait is
AssetBuildbut forAssetFieldimplementations. - Simple
Asset - Simple assets have no dependencies.
For this reason their
decodefunction is always sync and do not takeLoaderargument. - Trivial
Asset - Trivial assets have no dependencies and do not require building.
They are decoded directly from bytes.
And thus they implement
AssetBuild<B>for anyB.