diff --git a/CHANGELOG.md b/CHANGELOG.md index 4918b6b..76b0d47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## v0.8.0 - 04.11.2023 +- Update to Bevy 0.12 + ## v0.7.0 - 10.07.2023 - Update to Bevy 0.11 diff --git a/Cargo.toml b/Cargo.toml index cba6ed3..579b6e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_common_assets" -version = "0.7.0" +version = "0.8.0" authors = ["Niklas Eicker "] edition = "2021" license = "MIT OR Apache-2.0" @@ -21,18 +21,19 @@ msgpack = ["dep:rmp-serde"] xml = ["dep:quick-xml"] [dependencies] -bevy = { version = "0.11", default-features = false, features = ["bevy_asset"] } -serde_toml = { version = "0.7", package = "toml", optional = true } +bevy = { version = "0.12", default-features = false, features = ["bevy_asset"] } +serde_toml = { version = "0.8", package = "toml", optional = true } serde_ron = { version = "0.8", package = "ron", optional = true } serde_yaml = { version = "0.9", optional = true } serde_json = { version = "1", optional = true } rmp-serde = { version = "1", optional = true } -quick-xml = { version = "0.29", features = [ "serialize" ], optional = true } +thiserror = "1.0" +quick-xml = { version = "0.31", features = [ "serialize" ], optional = true } serde = { version = "1" } anyhow = { version = "1" } [dev-dependencies] -bevy = { version = "0.11" } +bevy = { version = "0.12" } serde = { version = "1" } [package.metadata.docs.rs] diff --git a/README.md b/README.md index 0dca1b6..8bc83a8 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,9 @@ Supported formats: Enable the feature(s) for the format(s) that you want to use. -Define the types that you would like to load from files and derive `serde::Deserialize`, `bevy::reflect::TypePath`, and `bevy::reflect::TypeUuid` for them. The last derive requires a unique uuid as an attribute: +Define the types that you would like to load from files and derive `serde::Deserialize`, `bevy::reflect::TypePath`, and `bevy::asset::Asset` for them. The last derive requires a unique uuid as an attribute: ```rust -#[derive(serde::Deserialize, bevy::reflect::TypeUuid, bevy::reflect::TypePath)] -#[uuid = "413be529-bfeb-41b3-9db0-4b8b380a2c46"] // <-- keep me unique +#[derive(serde::Deserialize, bevy::asset::Asset, bevy::reflect::TypePath)] struct Level { positions: Vec<[f32;3]>, } @@ -57,8 +56,7 @@ fn main() { .run(); } -#[derive(serde::Deserialize, bevy::reflect::TypeUuid, bevy::reflect::TypePath)] -#[uuid = "413be529-bfeb-41b3-9db0-4b8b380a2c46"] +#[derive(serde::Deserialize, bevy::asset::Asset, bevy::reflect::TypePath)] struct Level { positions: Vec<[f32; 3]>, } @@ -77,12 +75,13 @@ Compatibility of `bevy_common_assets` versions: | `bevy_common_assets` | `bevy` | |:---------------------|:-------| +| `0.8` | `0.12` | | `0.7` | `0.11` | | `0.5` - `0.6` | `0.10` | | `0.4` | `0.9` | | `0.3` | `0.8` | | `0.1` - `0.2` | `0.7` | -| `main` | `0.10` | +| `main` | `0.12` | | `bevy_main` | `main` | ## License diff --git a/examples/json.rs b/examples/json.rs index 64fdc87..ba38f20 100644 --- a/examples/json.rs +++ b/examples/json.rs @@ -1,5 +1,5 @@ use bevy::prelude::*; -use bevy::reflect::{TypePath, TypeUuid}; +use bevy::reflect::TypePath; use bevy_common_assets::json::JsonAssetPlugin; fn main() { @@ -44,8 +44,7 @@ fn spawn_level( } } -#[derive(serde::Deserialize, TypeUuid, TypePath)] -#[uuid = "413be529-bfeb-41b3-9db0-4b8b380a2c46"] +#[derive(serde::Deserialize, Asset, TypePath)] struct Level { positions: Vec<[f32; 3]>, } diff --git a/examples/msgpack.rs b/examples/msgpack.rs index 4bc6087..297ec30 100644 --- a/examples/msgpack.rs +++ b/examples/msgpack.rs @@ -1,5 +1,5 @@ use bevy::prelude::*; -use bevy::reflect::{TypePath, TypeUuid}; +use bevy::reflect::TypePath; use bevy_common_assets::msgpack::MsgPackAssetPlugin; fn main() { @@ -44,8 +44,7 @@ fn spawn_level( } } -#[derive(serde::Deserialize, TypeUuid, TypePath)] -#[uuid = "413be529-bfeb-41b3-9db0-4b8b380a2c46"] +#[derive(serde::Deserialize, Asset, TypePath)] struct Level { positions: Vec<[f32; 3]>, } diff --git a/examples/multiple_formats.rs b/examples/multiple_formats.rs index 25ca89e..6f7a6e4 100644 --- a/examples/multiple_formats.rs +++ b/examples/multiple_formats.rs @@ -1,6 +1,6 @@ use bevy::asset::LoadState; use bevy::prelude::*; -use bevy::reflect::{TypePath, TypeUuid}; +use bevy::reflect::TypePath; use bevy_common_assets::json::JsonAssetPlugin; use bevy_common_assets::ron::RonAssetPlugin; @@ -21,8 +21,7 @@ fn main() { .run(); } -#[derive(serde::Deserialize, TypeUuid, TypePath)] -#[uuid = "413be529-bfeb-41b3-9db0-4b8b380a2c46"] +#[derive(serde::Deserialize, Asset, TypePath)] struct Level { positions: Vec<[f32; 3]>, } @@ -60,11 +59,12 @@ fn check_loading( handles: Res, mut state: ResMut>, ) { - if asset_server.get_group_load_state(handles.0.iter().map(|handle| handle.id())) - == LoadState::Loaded - { - state.set(AppState::Level); + for handle in &handles.0 { + if asset_server.get_load_state(handle) != Some(LoadState::Loaded) { + return; + } } + state.set(AppState::Level); } #[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)] diff --git a/examples/ron.rs b/examples/ron.rs index eda0fc7..502cf3e 100644 --- a/examples/ron.rs +++ b/examples/ron.rs @@ -1,5 +1,5 @@ use bevy::prelude::*; -use bevy::reflect::{TypePath, TypeUuid}; +use bevy::reflect::TypePath; use bevy_common_assets::ron::RonAssetPlugin; fn main() { @@ -41,8 +41,7 @@ fn spawn_level( } } -#[derive(serde::Deserialize, TypeUuid, TypePath)] -#[uuid = "413be529-bfeb-41b3-9db0-4b8b380a2c46"] +#[derive(serde::Deserialize, Asset, TypePath)] struct Level { positions: Vec<[f32; 3]>, } diff --git a/examples/toml.rs b/examples/toml.rs index eece297..f08d88d 100644 --- a/examples/toml.rs +++ b/examples/toml.rs @@ -1,5 +1,5 @@ use bevy::prelude::*; -use bevy::reflect::{TypePath, TypeUuid}; +use bevy::reflect::TypePath; use bevy_common_assets::toml::TomlAssetPlugin; fn main() { @@ -44,8 +44,7 @@ fn spawn_level( } } -#[derive(serde::Deserialize, TypeUuid, TypePath)] -#[uuid = "413be529-bfeb-41b3-9db0-4b8b380a2c46"] +#[derive(serde::Deserialize, Asset, TypePath)] struct Level { positions: Vec<[f32; 3]>, } diff --git a/examples/xml.rs b/examples/xml.rs index 0059297..821efef 100644 --- a/examples/xml.rs +++ b/examples/xml.rs @@ -1,6 +1,6 @@ use bevy::math::f32::Vec3; use bevy::prelude::*; -use bevy::reflect::{TypePath, TypeUuid}; +use bevy::reflect::TypePath; use bevy_common_assets::xml::XmlAssetPlugin; fn main() { @@ -44,8 +44,7 @@ fn spawn_level( } } -#[derive(serde::Deserialize, TypeUuid, TypePath)] -#[uuid = "413be529-bfeb-41b3-9db0-4b8b380a2c46"] +#[derive(serde::Deserialize, Asset, TypePath)] struct Level { #[serde(rename = "Position")] positions: Vec, diff --git a/examples/yaml.rs b/examples/yaml.rs index f7a8496..59f9f49 100644 --- a/examples/yaml.rs +++ b/examples/yaml.rs @@ -1,5 +1,5 @@ use bevy::prelude::*; -use bevy::reflect::{TypePath, TypeUuid}; +use bevy::reflect::TypePath; use bevy_common_assets::yaml::YamlAssetPlugin; fn main() { @@ -44,8 +44,7 @@ fn spawn_level( } } -#[derive(serde::Deserialize, TypeUuid, TypePath)] -#[uuid = "413be529-bfeb-41b3-9db0-4b8b380a2c46"] +#[derive(serde::Deserialize, Asset, TypePath)] struct Level { positions: Vec<[f32; 3]>, } diff --git a/src/json.rs b/src/json.rs index d22d6cf..27fc450 100644 --- a/src/json.rs +++ b/src/json.rs @@ -1,7 +1,9 @@ use bevy::app::{App, Plugin}; -use bevy::asset::{AddAsset, Asset, AssetLoader, BoxedFuture, LoadContext, LoadedAsset}; +use bevy::asset::io::Reader; +use bevy::asset::{Asset, AssetApp, AssetLoader, AsyncReadExt, BoxedFuture, LoadContext}; use serde_json::from_slice; use std::marker::PhantomData; +use thiserror::Error; /// Plugin to load your asset type `A` from json files. pub struct JsonAssetPlugin { @@ -14,10 +16,11 @@ where for<'de> A: serde::Deserialize<'de> + Asset, { fn build(&self, app: &mut App) { - app.add_asset::().add_asset_loader(JsonAssetLoader:: { - extensions: self.extensions.clone(), - _marker: PhantomData, - }); + app.init_asset::() + .register_asset_loader(JsonAssetLoader:: { + extensions: self.extensions.clone(), + _marker: PhantomData, + }); } } @@ -39,19 +42,37 @@ struct JsonAssetLoader { _marker: PhantomData, } +/// Possible errors that can be produced by [`JsonAssetLoader`] +#[non_exhaustive] +#[derive(Debug, Error)] +pub enum JsonLoaderError { + /// An [IO Error](std::io::Error) + #[error("Could not read the file: {0}")] + Io(#[from] std::io::Error), + /// A [JSON Error](serde_json::error::Error) + #[error("Could not parse the JSON: {0}")] + JsonError(#[from] serde_json::error::Error), +} + impl AssetLoader for JsonAssetLoader where for<'de> A: serde::Deserialize<'de> + Asset, { + type Asset = A; + type Settings = (); + type Error = JsonLoaderError; + fn load<'a>( &'a self, - bytes: &'a [u8], - load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result<(), anyhow::Error>> { + reader: &'a mut Reader, + _settings: &'a (), + _load_context: &'a mut LoadContext, + ) -> BoxedFuture<'a, Result> { Box::pin(async move { - let asset = from_slice::(bytes)?; - load_context.set_default_asset(LoadedAsset::new(asset)); - Ok(()) + let mut bytes = Vec::new(); + reader.read_to_end(&mut bytes).await?; + let asset = from_slice::(&bytes)?; + Ok(asset) }) } diff --git a/src/lib.rs b/src/lib.rs index 5cdb839..42ec2a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ //! The following example requires the `json` feature and loads a custom asset from a json file. //! ``` //! use bevy::prelude::*; -//! use bevy::reflect::{TypeUuid, TypePath}; +//! use bevy::reflect::TypePath; //! # /* //! use bevy_common_assets::json::JsonAssetPlugin; //! # */ @@ -20,6 +20,7 @@ //! .add_plugins((DefaultPlugins, JsonAssetPlugin::::new(&["level.json"]))) //! # */ //! # .add_plugins((MinimalPlugins, AssetPlugin::default())) +//! # .init_asset::() //! .add_systems(Startup, load_level) //! # .add_systems(Update, stop) //! .run() @@ -30,8 +31,7 @@ //! commands.insert_resource(handle); //! } //! -//! #[derive(serde::Deserialize, TypeUuid, TypePath)] -//! #[uuid = "413be529-bfeb-41b3-9db0-4b8b380a2c46"] +//! #[derive(serde::Deserialize, Asset, TypePath)] //! struct Level { //! positions: Vec<[f32; 3]>, //! } diff --git a/src/msgpack.rs b/src/msgpack.rs index 2c5f615..ac0a343 100644 --- a/src/msgpack.rs +++ b/src/msgpack.rs @@ -1,7 +1,9 @@ use bevy::app::{App, Plugin}; -use bevy::asset::{AddAsset, Asset, AssetLoader, BoxedFuture, LoadContext, LoadedAsset}; +use bevy::asset::io::Reader; +use bevy::asset::{Asset, AssetApp, AssetLoader, AsyncReadExt, BoxedFuture, LoadContext}; use rmp_serde::from_slice; use std::marker::PhantomData; +use thiserror::Error; /// Plugin to load your asset type `A` from `MessagePack` files. pub struct MsgPackAssetPlugin { @@ -14,8 +16,8 @@ where for<'de> A: serde::Deserialize<'de> + Asset, { fn build(&self, app: &mut App) { - app.add_asset::() - .add_asset_loader(MsgPackAssetLoader:: { + app.init_asset::() + .register_asset_loader(MsgPackAssetLoader:: { extensions: self.extensions.clone(), _marker: PhantomData, }); @@ -40,19 +42,37 @@ struct MsgPackAssetLoader { _marker: PhantomData, } +/// Possible errors that can be produced by [`MsgPackAssetLoader`] +#[non_exhaustive] +#[derive(Debug, Error)] +pub enum MsgPackLoaderError { + /// An [IO Error](std::io::Error) + #[error("Could not read the file: {0}")] + Io(#[from] std::io::Error), + /// A [MessagePack Error](rmp_serde::decode::Error) + #[error("Could not parse MessagePack: {0}")] + MsgPackError(#[from] rmp_serde::decode::Error), +} + impl AssetLoader for MsgPackAssetLoader where for<'de> A: serde::Deserialize<'de> + Asset, { + type Asset = A; + type Settings = (); + type Error = MsgPackLoaderError; + fn load<'a>( &'a self, - bytes: &'a [u8], - load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result<(), anyhow::Error>> { + reader: &'a mut Reader, + _settings: &'a (), + _load_context: &'a mut LoadContext, + ) -> BoxedFuture<'a, Result> { Box::pin(async move { - let asset = from_slice::(bytes)?; - load_context.set_default_asset(LoadedAsset::new(asset)); - Ok(()) + let mut bytes = Vec::new(); + reader.read_to_end(&mut bytes).await?; + let asset = from_slice::(&bytes)?; + Ok(asset) }) } diff --git a/src/ron.rs b/src/ron.rs index 44ddc74..60c602e 100644 --- a/src/ron.rs +++ b/src/ron.rs @@ -1,7 +1,9 @@ use bevy::app::{App, Plugin}; -use bevy::asset::{AddAsset, Asset, AssetLoader, BoxedFuture, LoadContext, LoadedAsset}; +use bevy::asset::io::Reader; +use bevy::asset::{Asset, AssetApp, AssetLoader, AsyncReadExt, BoxedFuture, LoadContext}; use serde_ron::de::from_bytes; use std::marker::PhantomData; +use thiserror::Error; /// Plugin to load your asset type `A` from ron files. pub struct RonAssetPlugin { @@ -14,10 +16,11 @@ where for<'de> A: serde::Deserialize<'de> + Asset, { fn build(&self, app: &mut App) { - app.add_asset::().add_asset_loader(RonAssetLoader:: { - extensions: self.extensions.clone(), - _marker: PhantomData, - }); + app.init_asset::() + .register_asset_loader(RonAssetLoader:: { + extensions: self.extensions.clone(), + _marker: PhantomData, + }); } } @@ -39,19 +42,37 @@ struct RonAssetLoader { _marker: PhantomData, } +/// Possible errors that can be produced by [`RonAssetLoader`] +#[non_exhaustive] +#[derive(Debug, Error)] +pub enum RonLoaderError { + /// An [IO Error](std::io::Error) + #[error("Could not read the file: {0}")] + Io(#[from] std::io::Error), + /// A [RON Error](serde_ron::error::SpannedError) + #[error("Could not parse RON: {0}")] + RonError(#[from] serde_ron::error::SpannedError), +} + impl AssetLoader for RonAssetLoader where for<'de> A: serde::Deserialize<'de> + Asset, { + type Asset = A; + type Settings = (); + type Error = RonLoaderError; + fn load<'a>( &'a self, - bytes: &'a [u8], - load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result<(), anyhow::Error>> { + reader: &'a mut Reader, + _settings: &'a (), + _load_context: &'a mut LoadContext, + ) -> BoxedFuture<'a, Result> { Box::pin(async move { - let asset = from_bytes::(bytes)?; - load_context.set_default_asset(LoadedAsset::new(asset)); - Ok(()) + let mut bytes = Vec::new(); + reader.read_to_end(&mut bytes).await?; + let asset = from_bytes::(&bytes)?; + Ok(asset) }) } diff --git a/src/toml.rs b/src/toml.rs index 27ef8cd..a491b27 100644 --- a/src/toml.rs +++ b/src/toml.rs @@ -1,7 +1,9 @@ use bevy::app::{App, Plugin}; -use bevy::asset::{AddAsset, Asset, AssetLoader, BoxedFuture, LoadContext, LoadedAsset}; +use bevy::asset::io::Reader; +use bevy::asset::{Asset, AssetApp, AssetLoader, AsyncReadExt, BoxedFuture, LoadContext}; use std::marker::PhantomData; use std::str::from_utf8; +use thiserror::Error; /// Plugin to load your asset type `A` from toml files. pub struct TomlAssetPlugin { @@ -14,10 +16,11 @@ where for<'de> A: serde::Deserialize<'de> + Asset, { fn build(&self, app: &mut App) { - app.add_asset::().add_asset_loader(TomlAssetLoader:: { - extensions: self.extensions.clone(), - _marker: PhantomData, - }); + app.init_asset::() + .register_asset_loader(TomlAssetLoader:: { + extensions: self.extensions.clone(), + _marker: PhantomData, + }); } } @@ -39,19 +42,40 @@ struct TomlAssetLoader { _marker: PhantomData, } +/// Possible errors that can be produced by [`TomlAssetLoader`] +#[non_exhaustive] +#[derive(Debug, Error)] +pub enum TomlLoaderError { + /// An [IO Error](std::io::Error) + #[error("Could not read the file: {0}")] + Io(#[from] std::io::Error), + /// A [conversion Error](std::str::Utf8Error) + #[error("Could not interpret as UTF-8: {0}")] + FormatError(#[from] std::str::Utf8Error), + /// A [TOML Error](serde_toml::de::Error) + #[error("Could not parse TOML: {0}")] + TomlError(#[from] serde_toml::de::Error), +} + impl AssetLoader for TomlAssetLoader where for<'de> A: serde::Deserialize<'de> + Asset, { + type Asset = A; + type Settings = (); + type Error = TomlLoaderError; + fn load<'a>( &'a self, - bytes: &'a [u8], - load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result<(), anyhow::Error>> { + reader: &'a mut Reader, + _settings: &'a (), + _load_context: &'a mut LoadContext, + ) -> BoxedFuture<'a, Result> { Box::pin(async move { - let asset = serde_toml::from_str::(from_utf8(bytes)?)?; - load_context.set_default_asset(LoadedAsset::new(asset)); - Ok(()) + let mut bytes = Vec::new(); + reader.read_to_end(&mut bytes).await?; + let asset = serde_toml::from_str::(from_utf8(&bytes)?)?; + Ok(asset) }) } diff --git a/src/xml.rs b/src/xml.rs index 218ef89..15312c9 100644 --- a/src/xml.rs +++ b/src/xml.rs @@ -1,8 +1,10 @@ use bevy::app::{App, Plugin}; -use bevy::asset::{AddAsset, Asset, AssetLoader, BoxedFuture, LoadContext, LoadedAsset}; +use bevy::asset::io::Reader; +use bevy::asset::{Asset, AssetApp, AssetLoader, AsyncReadExt, BoxedFuture, LoadContext}; use quick_xml::de::from_str; use std::marker::PhantomData; use std::str::from_utf8; +use thiserror::Error; /// Plugin to load your asset type `A` from xml files. /// Read the [`quick_xml` docs](https://docs.rs/quick-xml/latest/quick_xml/de/) for tips on deserialization. @@ -16,10 +18,11 @@ where for<'de> A: serde::Deserialize<'de> + Asset, { fn build(&self, app: &mut App) { - app.add_asset::().add_asset_loader(XmlAssetLoader:: { - extensions: self.extensions.clone(), - _marker: PhantomData, - }); + app.init_asset::() + .register_asset_loader(XmlAssetLoader:: { + extensions: self.extensions.clone(), + _marker: PhantomData, + }); } } @@ -41,19 +44,40 @@ struct XmlAssetLoader { _marker: PhantomData, } +/// Possible errors that can be produced by [`XmlAssetLoader`] +#[non_exhaustive] +#[derive(Debug, Error)] +pub enum XmlLoaderError { + /// An [IO Error](std::io::Error) + #[error("Could not read the file: {0}")] + Io(#[from] std::io::Error), + /// A [conversion Error](std::str::Utf8Error) + #[error("Could not interpret as UTF-8: {0}")] + FormatError(#[from] std::str::Utf8Error), + /// A [XML Error](quick_xml::DeError) + #[error("Could not parse XML: {0}")] + XmlError(#[from] quick_xml::DeError), +} + impl AssetLoader for XmlAssetLoader where for<'de> A: serde::Deserialize<'de> + Asset, { + type Asset = A; + type Settings = (); + type Error = XmlLoaderError; + fn load<'a>( &'a self, - bytes: &'a [u8], - load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result<(), anyhow::Error>> { + reader: &'a mut Reader, + _settings: &'a (), + _load_context: &'a mut LoadContext, + ) -> BoxedFuture<'a, Result> { Box::pin(async move { - let asset = from_str::(from_utf8(bytes)?)?; - load_context.set_default_asset(LoadedAsset::new(asset)); - Ok(()) + let mut bytes = Vec::new(); + reader.read_to_end(&mut bytes).await?; + let asset = from_str::(from_utf8(&bytes)?)?; + Ok(asset) }) } diff --git a/src/yaml.rs b/src/yaml.rs index 11ef6f7..b855c55 100644 --- a/src/yaml.rs +++ b/src/yaml.rs @@ -1,7 +1,9 @@ use bevy::app::{App, Plugin}; -use bevy::asset::{AddAsset, Asset, AssetLoader, BoxedFuture, LoadContext, LoadedAsset}; +use bevy::asset::io::Reader; +use bevy::asset::{Asset, AssetApp, AssetLoader, AsyncReadExt, BoxedFuture, LoadContext}; use serde_yaml::from_slice; use std::marker::PhantomData; +use thiserror::Error; /// Plugin to load your asset type `A` from yaml files. pub struct YamlAssetPlugin { @@ -14,10 +16,11 @@ where for<'de> A: serde::Deserialize<'de> + Asset, { fn build(&self, app: &mut App) { - app.add_asset::().add_asset_loader(YamlAssetLoader:: { - extensions: self.extensions.clone(), - _marker: PhantomData, - }); + app.init_asset::() + .register_asset_loader(YamlAssetLoader:: { + extensions: self.extensions.clone(), + _marker: PhantomData, + }); } } @@ -39,19 +42,37 @@ struct YamlAssetLoader { _marker: PhantomData, } +/// Possible errors that can be produced by [`YamlAssetLoader`] +#[non_exhaustive] +#[derive(Debug, Error)] +pub enum YamlLoaderError { + /// An [IO Error](std::io::Error) + #[error("Could not read the file: {0}")] + Io(#[from] std::io::Error), + /// A [YAML Error](serde_yaml::Error) + #[error("Could not parse YAML: {0}")] + YamlError(#[from] serde_yaml::Error), +} + impl AssetLoader for YamlAssetLoader where for<'de> A: serde::Deserialize<'de> + Asset, { + type Asset = A; + type Settings = (); + type Error = YamlLoaderError; + fn load<'a>( &'a self, - bytes: &'a [u8], - load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result<(), anyhow::Error>> { + reader: &'a mut Reader, + _settings: &'a (), + _load_context: &'a mut LoadContext, + ) -> BoxedFuture<'a, Result> { Box::pin(async move { - let asset = from_slice::(bytes)?; - load_context.set_default_asset(LoadedAsset::new(asset)); - Ok(()) + let mut bytes = Vec::new(); + reader.read_to_end(&mut bytes).await?; + let asset = from_slice::(&bytes)?; + Ok(asset) }) }