From a5f15ba3adb81d592b6c612308dc4396036318f2 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Thu, 9 Nov 2023 01:45:45 +0400 Subject: [PATCH 1/2] return type-erased Errors in AssetLoader::load this fixes https://github.com/bevyengine/bevy/issues/10350 Previous change made in https://github.com/bevyengine/bevy/pull/10003 resulted in inability for users to have ?Sized errors, which caused usability issues with crates like anyhow. --- crates/bevy_asset/src/lib.rs | 8 +++----- crates/bevy_asset/src/loader.rs | 20 +++++++------------ crates/bevy_asset/src/meta.rs | 3 +-- crates/bevy_asset/src/processor/process.rs | 4 ++-- crates/bevy_asset/src/saver.rs | 12 +++++------ crates/bevy_asset/src/server/mod.rs | 6 +++--- crates/bevy_audio/src/audio_source.rs | 5 ++--- crates/bevy_gltf/src/loader.rs | 5 ++--- .../bevy_render/src/render_resource/shader.rs | 3 +-- .../src/texture/compressed_image_saver.rs | 4 ++-- .../src/texture/exr_texture_loader.rs | 3 +-- .../src/texture/hdr_texture_loader.rs | 3 +-- .../bevy_render/src/texture/image_loader.rs | 3 +-- crates/bevy_scene/src/scene_loader.rs | 3 +-- crates/bevy_text/src/font_loader.rs | 3 +-- examples/asset/custom_asset.rs | 3 +-- examples/asset/processing/asset_processing.rs | 11 +++------- 17 files changed, 37 insertions(+), 62 deletions(-) diff --git a/crates/bevy_asset/src/lib.rs b/crates/bevy_asset/src/lib.rs index 9f9cd44c77b0d..17ad7c5fc7897 100644 --- a/crates/bevy_asset/src/lib.rs +++ b/crates/bevy_asset/src/lib.rs @@ -89,7 +89,7 @@ pub enum AssetMode { /// /// When developing an app, you should enable the `asset_processor` cargo feature, which will run the asset processor at startup. This should generally /// be used in combination with the `file_watcher` cargo feature, which enables hot-reloading of assets that have changed. When both features are enabled, - /// changes to "original/source assets" will be detected, the asset will be re-processed, and then the final processed asset will be hot-reloaded in the app. + /// changes to "original/source assets" will be detected, the asset will be re-processed, and then the final processed asset will be hot-reloaded in the app. /// /// [`AssetMeta`]: crate::meta::AssetMeta /// [`AssetSource`]: crate::io::AssetSource @@ -459,14 +459,12 @@ mod tests { type Settings = (); - type Error = CoolTextLoaderError; - fn load<'a>( &'a self, reader: &'a mut Reader, _settings: &'a Self::Settings, load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { let mut bytes = Vec::new(); reader.read_to_end(&mut bytes).await?; @@ -474,7 +472,7 @@ mod tests { let mut embedded = String::new(); for dep in ron.embedded_dependencies { let loaded = load_context.load_direct(&dep).await.map_err(|_| { - Self::Error::CannotLoadDependency { + CoolTextLoaderError::CannotLoadDependency { dependency: dep.into(), } })?; diff --git a/crates/bevy_asset/src/loader.rs b/crates/bevy_asset/src/loader.rs index 3a5bbc7d032aa..c6564de2b6a20 100644 --- a/crates/bevy_asset/src/loader.rs +++ b/crates/bevy_asset/src/loader.rs @@ -20,6 +20,8 @@ use std::{ }; use thiserror::Error; +pub type Error = Box; + /// Loads an [`Asset`] from a given byte [`Reader`]. This can accept [`AssetLoader::Settings`], which configure how the [`Asset`] /// should be loaded. pub trait AssetLoader: Send + Sync + 'static { @@ -27,15 +29,13 @@ pub trait AssetLoader: Send + Sync + 'static { type Asset: crate::Asset; /// The settings type used by this [`AssetLoader`]. type Settings: Settings + Default + Serialize + for<'a> Deserialize<'a>; - /// The type of [error](`std::error::Error`) which could be encountered by this loader. - type Error: std::error::Error + Send + Sync + 'static; /// Asynchronously loads [`AssetLoader::Asset`] (and any other labeled assets) from the bytes provided by [`Reader`]. fn load<'a>( &'a self, reader: &'a mut Reader, settings: &'a Self::Settings, load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result>; + ) -> BoxedFuture<'a, Result>; /// Returns a list of extensions supported by this asset loader, without the preceding dot. fn extensions(&self) -> &[&str]; @@ -49,10 +49,7 @@ pub trait ErasedAssetLoader: Send + Sync + 'static { reader: &'a mut Reader, meta: Box, load_context: LoadContext<'a>, - ) -> BoxedFuture< - 'a, - Result>, - >; + ) -> BoxedFuture<'a, Result>; /// Returns a list of extensions supported by this asset loader, without the preceding dot. fn extensions(&self) -> &[&str]; @@ -80,10 +77,7 @@ where reader: &'a mut Reader, meta: Box, mut load_context: LoadContext<'a>, - ) -> BoxedFuture< - 'a, - Result>, - > { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { let settings = meta .loader_settings() @@ -446,7 +440,7 @@ impl<'a> LoadContext<'a> { /// Retrieves a handle for the asset at the given path and adds that path as a dependency of the asset. /// If the current context is a normal [`AssetServer::load`], an actual asset load will be kicked off immediately, which ensures the load happens /// as soon as possible. - /// "Normal loads" kicked from within a normal Bevy App will generally configure the context to kick off loads immediately. + /// "Normal loads" kicked from within a normal Bevy App will generally configure the context to kick off loads immediately. /// If the current context is configured to not load dependencies automatically (ex: [`AssetProcessor`](crate::processor::AssetProcessor)), /// a load will not be kicked off automatically. It is then the calling context's responsibility to begin a load if necessary. pub fn load<'b, A: Asset>(&mut self, path: impl Into>) -> Handle { @@ -462,7 +456,7 @@ impl<'a> LoadContext<'a> { /// Loads the [`Asset`] of type `A` at the given `path` with the given [`AssetLoader::Settings`] settings `S`. This is a "deferred" /// load. If the settings type `S` does not match the settings expected by `A`'s asset loader, an error will be printed to the log - /// and the asset load will fail. + /// and the asset load will fail. pub fn load_with_settings<'b, A: Asset, S: Settings + Default>( &mut self, path: impl Into>, diff --git a/crates/bevy_asset/src/meta.rs b/crates/bevy_asset/src/meta.rs index dbcd7d7feb57d..01574a3ff7880 100644 --- a/crates/bevy_asset/src/meta.rs +++ b/crates/bevy_asset/src/meta.rs @@ -193,13 +193,12 @@ impl VisitAssetDependencies for () { impl AssetLoader for () { type Asset = (); type Settings = (); - type Error = std::io::Error; fn load<'a>( &'a self, _reader: &'a mut crate::io::Reader, _settings: &'a Self::Settings, _load_context: &'a mut crate::LoadContext, - ) -> bevy_utils::BoxedFuture<'a, Result> { + ) -> bevy_utils::BoxedFuture<'a, Result> { unreachable!(); } diff --git a/crates/bevy_asset/src/processor/process.rs b/crates/bevy_asset/src/processor/process.rs index ef6a3fbb2f5c5..33e601b3a07e3 100644 --- a/crates/bevy_asset/src/processor/process.rs +++ b/crates/bevy_asset/src/processor/process.rs @@ -107,7 +107,7 @@ pub enum ProcessError { #[error("The wrong meta type was passed into a processor. This is probably an internal implementation error.")] WrongMetaType, #[error("Encountered an error while saving the asset: {0}")] - AssetSaveError(#[from] Box), + AssetSaveError(#[from] crate::Error), #[error("Assets without extensions are not supported.")] ExtensionRequired, } @@ -138,7 +138,7 @@ impl> Process .saver .save(writer, saved_asset, &settings.saver_settings) .await - .map_err(|error| ProcessError::AssetSaveError(Box::new(error)))?; + .map_err(ProcessError::AssetSaveError)?; Ok(output_settings) }) } diff --git a/crates/bevy_asset/src/saver.rs b/crates/bevy_asset/src/saver.rs index 0b01b7d91e550..5d8f77ce3d32a 100644 --- a/crates/bevy_asset/src/saver.rs +++ b/crates/bevy_asset/src/saver.rs @@ -13,29 +13,27 @@ pub trait AssetSaver: Send + Sync + 'static { type Settings: Settings + Default + Serialize + for<'a> Deserialize<'a>; /// The type of [`AssetLoader`] used to load this [`Asset`] type OutputLoader: AssetLoader; - /// The type of [error](`std::error::Error`) which could be encountered by this saver. - type Error: std::error::Error + Send + Sync + 'static; /// Saves the given runtime [`Asset`] by writing it to a byte format using `writer`. The passed in `settings` can influence how the - /// `asset` is saved. + /// `asset` is saved. fn save<'a>( &'a self, writer: &'a mut Writer, asset: SavedAsset<'a, Self::Asset>, settings: &'a Self::Settings, - ) -> BoxedFuture<'a, Result<::Settings, Self::Error>>; + ) -> BoxedFuture<'a, Result<::Settings, crate::Error>>; } /// A type-erased dynamic variant of [`AssetSaver`] that allows callers to save assets without knowing the actual type of the [`AssetSaver`]. pub trait ErasedAssetSaver: Send + Sync + 'static { /// Saves the given runtime [`ErasedLoadedAsset`] by writing it to a byte format using `writer`. The passed in `settings` can influence how the - /// `asset` is saved. + /// `asset` is saved. fn save<'a>( &'a self, writer: &'a mut Writer, asset: &'a ErasedLoadedAsset, settings: &'a dyn Settings, - ) -> BoxedFuture<'a, Result<(), Box>>; + ) -> BoxedFuture<'a, Result<(), crate::Error>>; /// The type name of the [`AssetSaver`]. fn type_name(&self) -> &'static str; @@ -47,7 +45,7 @@ impl ErasedAssetSaver for S { writer: &'a mut Writer, asset: &'a ErasedLoadedAsset, settings: &'a dyn Settings, - ) -> BoxedFuture<'a, Result<(), Box>> { + ) -> BoxedFuture<'a, Result<(), crate::Error>> { Box::pin(async move { let settings = settings .downcast_ref::() diff --git a/crates/bevy_asset/src/server/mod.rs b/crates/bevy_asset/src/server/mod.rs index 864faf70fc71b..780b2713ea14b 100644 --- a/crates/bevy_asset/src/server/mod.rs +++ b/crates/bevy_asset/src/server/mod.rs @@ -33,7 +33,7 @@ use thiserror::Error; /// The general process to load an asset is: /// 1. Initialize a new [`Asset`] type with the [`AssetServer`] via [`AssetApp::init_asset`], which will internally call [`AssetServer::register_asset`] /// and set up related ECS [`Assets`] storage and systems. -/// 2. Register one or more [`AssetLoader`]s for that asset with [`AssetApp::init_asset_loader`] +/// 2. Register one or more [`AssetLoader`]s for that asset with [`AssetApp::init_asset_loader`] /// 3. Add the asset to your asset folder (defaults to `assets`). /// 4. Call [`AssetServer::load`] with a path to your asset. /// @@ -957,7 +957,7 @@ enum MaybeAssetLoader { }, } -/// Internal events for asset load results +/// Internal events for asset load results #[allow(clippy::large_enum_variant)] pub(crate) enum InternalAssetEvent { Loaded { @@ -1046,7 +1046,7 @@ pub enum AssetLoadError { AssetLoaderError { path: AssetPath<'static>, loader_name: &'static str, - error: Box, + error: crate::Error, }, #[error("The file at '{base_path}' does not contain the labeled asset '{label}'.")] MissingLabel { diff --git a/crates/bevy_audio/src/audio_source.rs b/crates/bevy_audio/src/audio_source.rs index 30f9c8cf8da9e..8f3509bc051fd 100644 --- a/crates/bevy_audio/src/audio_source.rs +++ b/crates/bevy_audio/src/audio_source.rs @@ -41,14 +41,13 @@ pub struct AudioLoader; impl AssetLoader for AudioLoader { type Asset = AudioSource; type Settings = (); - type Error = std::io::Error; fn load<'a>( &'a self, reader: &'a mut Reader, _settings: &'a Self::Settings, _load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { let mut bytes = Vec::new(); reader.read_to_end(&mut bytes).await?; @@ -113,7 +112,7 @@ pub trait AddAudioSource { /// so that it can be converted to a [`rodio::Source`] type, /// and [`Asset`], so that it can be registered as an asset. /// To use this method on [`App`][bevy_app::App], - /// the [audio][super::AudioPlugin] and [asset][bevy_asset::AssetPlugin] plugins must be added first. + /// the [audio][super::AudioPlugin] and [asset][bevy_asset::AssetPlugin] plugins must be added first. fn add_audio_source(&mut self) -> &mut Self where T: Decodable + Asset, diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index abdbc1a3cbe50..e5b35ffaba316 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -108,17 +108,16 @@ pub struct GltfLoader { impl AssetLoader for GltfLoader { type Asset = Gltf; type Settings = (); - type Error = GltfError; fn load<'a>( &'a self, reader: &'a mut Reader, _settings: &'a (), load_context: &'a mut LoadContext, - ) -> bevy_utils::BoxedFuture<'a, Result> { + ) -> bevy_utils::BoxedFuture<'a, Result> { Box::pin(async move { let mut bytes = Vec::new(); reader.read_to_end(&mut bytes).await?; - load_gltf(self, &bytes, load_context).await + Ok(load_gltf(self, &bytes, load_context).await?) }) } diff --git a/crates/bevy_render/src/render_resource/shader.rs b/crates/bevy_render/src/render_resource/shader.rs index 465fbb193d35a..71b140fadf19f 100644 --- a/crates/bevy_render/src/render_resource/shader.rs +++ b/crates/bevy_render/src/render_resource/shader.rs @@ -250,13 +250,12 @@ pub enum ShaderLoaderError { impl AssetLoader for ShaderLoader { type Asset = Shader; type Settings = (); - type Error = ShaderLoaderError; fn load<'a>( &'a self, reader: &'a mut Reader, _settings: &'a Self::Settings, load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { let ext = load_context.path().extension().unwrap().to_str().unwrap(); diff --git a/crates/bevy_render/src/texture/compressed_image_saver.rs b/crates/bevy_render/src/texture/compressed_image_saver.rs index 5fe533ba196c4..0e48a1b3fe752 100644 --- a/crates/bevy_render/src/texture/compressed_image_saver.rs +++ b/crates/bevy_render/src/texture/compressed_image_saver.rs @@ -17,14 +17,14 @@ impl AssetSaver for CompressedImageSaver { type Settings = (); type OutputLoader = ImageLoader; - type Error = CompressedImageSaverError; fn save<'a>( &'a self, writer: &'a mut bevy_asset::io::Writer, image: SavedAsset<'a, Self::Asset>, _settings: &'a Self::Settings, - ) -> bevy_utils::BoxedFuture<'a, std::result::Result> { + ) -> bevy_utils::BoxedFuture<'a, std::result::Result> + { // PERF: this should live inside the future, but CompressorParams and Compressor are not Send / can't be owned by the BoxedFuture (which _is_ Send) let mut compressor_params = basis_universal::CompressorParams::new(); compressor_params.set_basis_format(basis_universal::BasisTextureFormat::UASTC4x4); diff --git a/crates/bevy_render/src/texture/exr_texture_loader.rs b/crates/bevy_render/src/texture/exr_texture_loader.rs index e5494e9935d52..2e1c882f595bb 100644 --- a/crates/bevy_render/src/texture/exr_texture_loader.rs +++ b/crates/bevy_render/src/texture/exr_texture_loader.rs @@ -25,14 +25,13 @@ pub enum ExrTextureLoaderError { impl AssetLoader for ExrTextureLoader { type Asset = Image; type Settings = (); - type Error = ExrTextureLoaderError; fn load<'a>( &'a self, reader: &'a mut Reader, _settings: &'a Self::Settings, _load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { let format = TextureFormat::Rgba32Float; debug_assert_eq!( diff --git a/crates/bevy_render/src/texture/hdr_texture_loader.rs b/crates/bevy_render/src/texture/hdr_texture_loader.rs index e54b38b806606..c2c3be924bb23 100644 --- a/crates/bevy_render/src/texture/hdr_texture_loader.rs +++ b/crates/bevy_render/src/texture/hdr_texture_loader.rs @@ -19,13 +19,12 @@ pub enum HdrTextureLoaderError { impl AssetLoader for HdrTextureLoader { type Asset = Image; type Settings = (); - type Error = HdrTextureLoaderError; fn load<'a>( &'a self, reader: &'a mut Reader, _settings: &'a (), _load_context: &'a mut LoadContext, - ) -> bevy_utils::BoxedFuture<'a, Result> { + ) -> bevy_utils::BoxedFuture<'a, Result> { Box::pin(async move { let format = TextureFormat::Rgba32Float; debug_assert_eq!( diff --git a/crates/bevy_render/src/texture/image_loader.rs b/crates/bevy_render/src/texture/image_loader.rs index ec79c9d13e4cb..e95a8f2b07dbd 100644 --- a/crates/bevy_render/src/texture/image_loader.rs +++ b/crates/bevy_render/src/texture/image_loader.rs @@ -81,13 +81,12 @@ pub enum ImageLoaderError { impl AssetLoader for ImageLoader { type Asset = Image; type Settings = ImageLoaderSettings; - type Error = ImageLoaderError; fn load<'a>( &'a self, reader: &'a mut Reader, settings: &'a ImageLoaderSettings, load_context: &'a mut LoadContext, - ) -> bevy_utils::BoxedFuture<'a, Result> { + ) -> bevy_utils::BoxedFuture<'a, Result> { Box::pin(async move { // use the file extension for the image type let ext = load_context.path().extension().unwrap().to_str().unwrap(); diff --git a/crates/bevy_scene/src/scene_loader.rs b/crates/bevy_scene/src/scene_loader.rs index 5d1e4de56ade4..858a015ffc1fb 100644 --- a/crates/bevy_scene/src/scene_loader.rs +++ b/crates/bevy_scene/src/scene_loader.rs @@ -41,14 +41,13 @@ pub enum SceneLoaderError { impl AssetLoader for SceneLoader { type Asset = DynamicScene; type Settings = (); - type Error = SceneLoaderError; fn load<'a>( &'a self, reader: &'a mut Reader, _settings: &'a (), _load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { let mut bytes = Vec::new(); reader.read_to_end(&mut bytes).await?; diff --git a/crates/bevy_text/src/font_loader.rs b/crates/bevy_text/src/font_loader.rs index a47abbd9619a0..f9789af19355b 100644 --- a/crates/bevy_text/src/font_loader.rs +++ b/crates/bevy_text/src/font_loader.rs @@ -20,13 +20,12 @@ pub enum FontLoaderError { impl AssetLoader for FontLoader { type Asset = Font; type Settings = (); - type Error = FontLoaderError; fn load<'a>( &'a self, reader: &'a mut Reader, _settings: &'a (), _load_context: &'a mut LoadContext, - ) -> bevy_utils::BoxedFuture<'a, Result> { + ) -> bevy_utils::BoxedFuture<'a, Result> { Box::pin(async move { let mut bytes = Vec::new(); reader.read_to_end(&mut bytes).await?; diff --git a/examples/asset/custom_asset.rs b/examples/asset/custom_asset.rs index c0aa0ad9b83b9..682f31bf73fa4 100644 --- a/examples/asset/custom_asset.rs +++ b/examples/asset/custom_asset.rs @@ -34,13 +34,12 @@ pub enum CustomAssetLoaderError { impl AssetLoader for CustomAssetLoader { type Asset = CustomAsset; type Settings = (); - type Error = CustomAssetLoaderError; fn load<'a>( &'a self, reader: &'a mut Reader, _settings: &'a (), _load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { let mut bytes = Vec::new(); reader.read_to_end(&mut bytes).await?; diff --git a/examples/asset/processing/asset_processing.rs b/examples/asset/processing/asset_processing.rs index 92c2884b627ab..d6de283c9f284 100644 --- a/examples/asset/processing/asset_processing.rs +++ b/examples/asset/processing/asset_processing.rs @@ -79,13 +79,12 @@ struct TextSettings { impl AssetLoader for TextLoader { type Asset = Text; type Settings = TextSettings; - type Error = std::io::Error; fn load<'a>( &'a self, reader: &'a mut Reader, settings: &'a TextSettings, _load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { let mut bytes = Vec::new(); reader.read_to_end(&mut bytes).await?; @@ -132,17 +131,14 @@ enum CoolTextLoaderError { impl AssetLoader for CoolTextLoader { type Asset = CoolText; - type Settings = (); - type Error = CoolTextLoaderError; - fn load<'a>( &'a self, reader: &'a mut Reader, _settings: &'a Self::Settings, load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { let mut bytes = Vec::new(); reader.read_to_end(&mut bytes).await?; @@ -180,14 +176,13 @@ impl AssetSaver for CoolTextSaver { type Asset = CoolText; type Settings = CoolTextSaverSettings; type OutputLoader = TextLoader; - type Error = std::io::Error; fn save<'a>( &'a self, writer: &'a mut Writer, asset: SavedAsset<'a, Self::Asset>, settings: &'a Self::Settings, - ) -> BoxedFuture<'a, Result> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { let text = format!("{}{}", asset.text.clone(), settings.appended); writer.write_all(text.as_bytes()).await?; From fe95a31fe4bf87b8bc20901de871c98247439b3d Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Thu, 9 Nov 2023 02:40:49 +0400 Subject: [PATCH 2/2] bevy::asset::Error -> bevy::asset::BoxedError --- crates/bevy_asset/src/lib.rs | 2 +- crates/bevy_asset/src/loader.rs | 8 ++++---- crates/bevy_asset/src/meta.rs | 2 +- crates/bevy_asset/src/processor/process.rs | 2 +- crates/bevy_asset/src/saver.rs | 6 +++--- crates/bevy_asset/src/server/mod.rs | 2 +- crates/bevy_audio/src/audio_source.rs | 2 +- crates/bevy_gltf/src/loader.rs | 2 +- crates/bevy_render/src/render_resource/shader.rs | 2 +- crates/bevy_render/src/texture/compressed_image_saver.rs | 2 +- crates/bevy_render/src/texture/exr_texture_loader.rs | 2 +- crates/bevy_render/src/texture/hdr_texture_loader.rs | 2 +- crates/bevy_render/src/texture/image_loader.rs | 2 +- crates/bevy_scene/src/scene_loader.rs | 2 +- crates/bevy_text/src/font_loader.rs | 2 +- examples/asset/custom_asset.rs | 2 +- examples/asset/processing/asset_processing.rs | 6 +++--- 17 files changed, 24 insertions(+), 24 deletions(-) diff --git a/crates/bevy_asset/src/lib.rs b/crates/bevy_asset/src/lib.rs index 17ad7c5fc7897..e54d8f71f975b 100644 --- a/crates/bevy_asset/src/lib.rs +++ b/crates/bevy_asset/src/lib.rs @@ -464,7 +464,7 @@ mod tests { reader: &'a mut Reader, _settings: &'a Self::Settings, load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { let mut bytes = Vec::new(); reader.read_to_end(&mut bytes).await?; diff --git a/crates/bevy_asset/src/loader.rs b/crates/bevy_asset/src/loader.rs index c6564de2b6a20..1d0aac53c88cb 100644 --- a/crates/bevy_asset/src/loader.rs +++ b/crates/bevy_asset/src/loader.rs @@ -20,7 +20,7 @@ use std::{ }; use thiserror::Error; -pub type Error = Box; +pub type BoxedError = Box; /// Loads an [`Asset`] from a given byte [`Reader`]. This can accept [`AssetLoader::Settings`], which configure how the [`Asset`] /// should be loaded. @@ -35,7 +35,7 @@ pub trait AssetLoader: Send + Sync + 'static { reader: &'a mut Reader, settings: &'a Self::Settings, load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result>; + ) -> BoxedFuture<'a, Result>; /// Returns a list of extensions supported by this asset loader, without the preceding dot. fn extensions(&self) -> &[&str]; @@ -49,7 +49,7 @@ pub trait ErasedAssetLoader: Send + Sync + 'static { reader: &'a mut Reader, meta: Box, load_context: LoadContext<'a>, - ) -> BoxedFuture<'a, Result>; + ) -> BoxedFuture<'a, Result>; /// Returns a list of extensions supported by this asset loader, without the preceding dot. fn extensions(&self) -> &[&str]; @@ -77,7 +77,7 @@ where reader: &'a mut Reader, meta: Box, mut load_context: LoadContext<'a>, - ) -> BoxedFuture<'a, Result> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { let settings = meta .loader_settings() diff --git a/crates/bevy_asset/src/meta.rs b/crates/bevy_asset/src/meta.rs index 01574a3ff7880..57c07fc313c6e 100644 --- a/crates/bevy_asset/src/meta.rs +++ b/crates/bevy_asset/src/meta.rs @@ -198,7 +198,7 @@ impl AssetLoader for () { _reader: &'a mut crate::io::Reader, _settings: &'a Self::Settings, _load_context: &'a mut crate::LoadContext, - ) -> bevy_utils::BoxedFuture<'a, Result> { + ) -> bevy_utils::BoxedFuture<'a, Result> { unreachable!(); } diff --git a/crates/bevy_asset/src/processor/process.rs b/crates/bevy_asset/src/processor/process.rs index 33e601b3a07e3..df4b7fe775155 100644 --- a/crates/bevy_asset/src/processor/process.rs +++ b/crates/bevy_asset/src/processor/process.rs @@ -107,7 +107,7 @@ pub enum ProcessError { #[error("The wrong meta type was passed into a processor. This is probably an internal implementation error.")] WrongMetaType, #[error("Encountered an error while saving the asset: {0}")] - AssetSaveError(#[from] crate::Error), + AssetSaveError(#[from] crate::BoxedError), #[error("Assets without extensions are not supported.")] ExtensionRequired, } diff --git a/crates/bevy_asset/src/saver.rs b/crates/bevy_asset/src/saver.rs index 5d8f77ce3d32a..83300809382a7 100644 --- a/crates/bevy_asset/src/saver.rs +++ b/crates/bevy_asset/src/saver.rs @@ -21,7 +21,7 @@ pub trait AssetSaver: Send + Sync + 'static { writer: &'a mut Writer, asset: SavedAsset<'a, Self::Asset>, settings: &'a Self::Settings, - ) -> BoxedFuture<'a, Result<::Settings, crate::Error>>; + ) -> BoxedFuture<'a, Result<::Settings, crate::BoxedError>>; } /// A type-erased dynamic variant of [`AssetSaver`] that allows callers to save assets without knowing the actual type of the [`AssetSaver`]. @@ -33,7 +33,7 @@ pub trait ErasedAssetSaver: Send + Sync + 'static { writer: &'a mut Writer, asset: &'a ErasedLoadedAsset, settings: &'a dyn Settings, - ) -> BoxedFuture<'a, Result<(), crate::Error>>; + ) -> BoxedFuture<'a, Result<(), crate::BoxedError>>; /// The type name of the [`AssetSaver`]. fn type_name(&self) -> &'static str; @@ -45,7 +45,7 @@ impl ErasedAssetSaver for S { writer: &'a mut Writer, asset: &'a ErasedLoadedAsset, settings: &'a dyn Settings, - ) -> BoxedFuture<'a, Result<(), crate::Error>> { + ) -> BoxedFuture<'a, Result<(), crate::BoxedError>> { Box::pin(async move { let settings = settings .downcast_ref::() diff --git a/crates/bevy_asset/src/server/mod.rs b/crates/bevy_asset/src/server/mod.rs index 780b2713ea14b..1c383113e9fb5 100644 --- a/crates/bevy_asset/src/server/mod.rs +++ b/crates/bevy_asset/src/server/mod.rs @@ -1046,7 +1046,7 @@ pub enum AssetLoadError { AssetLoaderError { path: AssetPath<'static>, loader_name: &'static str, - error: crate::Error, + error: crate::BoxedError, }, #[error("The file at '{base_path}' does not contain the labeled asset '{label}'.")] MissingLabel { diff --git a/crates/bevy_audio/src/audio_source.rs b/crates/bevy_audio/src/audio_source.rs index 8f3509bc051fd..aeaef15532d89 100644 --- a/crates/bevy_audio/src/audio_source.rs +++ b/crates/bevy_audio/src/audio_source.rs @@ -47,7 +47,7 @@ impl AssetLoader for AudioLoader { reader: &'a mut Reader, _settings: &'a Self::Settings, _load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { let mut bytes = Vec::new(); reader.read_to_end(&mut bytes).await?; diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index e5b35ffaba316..6dd569a98f43a 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -113,7 +113,7 @@ impl AssetLoader for GltfLoader { reader: &'a mut Reader, _settings: &'a (), load_context: &'a mut LoadContext, - ) -> bevy_utils::BoxedFuture<'a, Result> { + ) -> bevy_utils::BoxedFuture<'a, Result> { Box::pin(async move { let mut bytes = Vec::new(); reader.read_to_end(&mut bytes).await?; diff --git a/crates/bevy_render/src/render_resource/shader.rs b/crates/bevy_render/src/render_resource/shader.rs index 71b140fadf19f..aa2e102d7e1a4 100644 --- a/crates/bevy_render/src/render_resource/shader.rs +++ b/crates/bevy_render/src/render_resource/shader.rs @@ -255,7 +255,7 @@ impl AssetLoader for ShaderLoader { reader: &'a mut Reader, _settings: &'a Self::Settings, load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { let ext = load_context.path().extension().unwrap().to_str().unwrap(); diff --git a/crates/bevy_render/src/texture/compressed_image_saver.rs b/crates/bevy_render/src/texture/compressed_image_saver.rs index 0e48a1b3fe752..6f5d58a89d86c 100644 --- a/crates/bevy_render/src/texture/compressed_image_saver.rs +++ b/crates/bevy_render/src/texture/compressed_image_saver.rs @@ -23,7 +23,7 @@ impl AssetSaver for CompressedImageSaver { writer: &'a mut bevy_asset::io::Writer, image: SavedAsset<'a, Self::Asset>, _settings: &'a Self::Settings, - ) -> bevy_utils::BoxedFuture<'a, std::result::Result> + ) -> bevy_utils::BoxedFuture<'a, std::result::Result> { // PERF: this should live inside the future, but CompressorParams and Compressor are not Send / can't be owned by the BoxedFuture (which _is_ Send) let mut compressor_params = basis_universal::CompressorParams::new(); diff --git a/crates/bevy_render/src/texture/exr_texture_loader.rs b/crates/bevy_render/src/texture/exr_texture_loader.rs index 2e1c882f595bb..7d1daa8adbe94 100644 --- a/crates/bevy_render/src/texture/exr_texture_loader.rs +++ b/crates/bevy_render/src/texture/exr_texture_loader.rs @@ -31,7 +31,7 @@ impl AssetLoader for ExrTextureLoader { reader: &'a mut Reader, _settings: &'a Self::Settings, _load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { let format = TextureFormat::Rgba32Float; debug_assert_eq!( diff --git a/crates/bevy_render/src/texture/hdr_texture_loader.rs b/crates/bevy_render/src/texture/hdr_texture_loader.rs index c2c3be924bb23..71bffda00f4c7 100644 --- a/crates/bevy_render/src/texture/hdr_texture_loader.rs +++ b/crates/bevy_render/src/texture/hdr_texture_loader.rs @@ -24,7 +24,7 @@ impl AssetLoader for HdrTextureLoader { reader: &'a mut Reader, _settings: &'a (), _load_context: &'a mut LoadContext, - ) -> bevy_utils::BoxedFuture<'a, Result> { + ) -> bevy_utils::BoxedFuture<'a, Result> { Box::pin(async move { let format = TextureFormat::Rgba32Float; debug_assert_eq!( diff --git a/crates/bevy_render/src/texture/image_loader.rs b/crates/bevy_render/src/texture/image_loader.rs index e95a8f2b07dbd..f93b52e0cfd40 100644 --- a/crates/bevy_render/src/texture/image_loader.rs +++ b/crates/bevy_render/src/texture/image_loader.rs @@ -86,7 +86,7 @@ impl AssetLoader for ImageLoader { reader: &'a mut Reader, settings: &'a ImageLoaderSettings, load_context: &'a mut LoadContext, - ) -> bevy_utils::BoxedFuture<'a, Result> { + ) -> bevy_utils::BoxedFuture<'a, Result> { Box::pin(async move { // use the file extension for the image type let ext = load_context.path().extension().unwrap().to_str().unwrap(); diff --git a/crates/bevy_scene/src/scene_loader.rs b/crates/bevy_scene/src/scene_loader.rs index 858a015ffc1fb..c18eab9acba58 100644 --- a/crates/bevy_scene/src/scene_loader.rs +++ b/crates/bevy_scene/src/scene_loader.rs @@ -47,7 +47,7 @@ impl AssetLoader for SceneLoader { reader: &'a mut Reader, _settings: &'a (), _load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { let mut bytes = Vec::new(); reader.read_to_end(&mut bytes).await?; diff --git a/crates/bevy_text/src/font_loader.rs b/crates/bevy_text/src/font_loader.rs index f9789af19355b..8f86d7e1e5cd9 100644 --- a/crates/bevy_text/src/font_loader.rs +++ b/crates/bevy_text/src/font_loader.rs @@ -25,7 +25,7 @@ impl AssetLoader for FontLoader { reader: &'a mut Reader, _settings: &'a (), _load_context: &'a mut LoadContext, - ) -> bevy_utils::BoxedFuture<'a, Result> { + ) -> bevy_utils::BoxedFuture<'a, Result> { Box::pin(async move { let mut bytes = Vec::new(); reader.read_to_end(&mut bytes).await?; diff --git a/examples/asset/custom_asset.rs b/examples/asset/custom_asset.rs index 682f31bf73fa4..8007ef255a4f3 100644 --- a/examples/asset/custom_asset.rs +++ b/examples/asset/custom_asset.rs @@ -39,7 +39,7 @@ impl AssetLoader for CustomAssetLoader { reader: &'a mut Reader, _settings: &'a (), _load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { let mut bytes = Vec::new(); reader.read_to_end(&mut bytes).await?; diff --git a/examples/asset/processing/asset_processing.rs b/examples/asset/processing/asset_processing.rs index d6de283c9f284..038f52b15599f 100644 --- a/examples/asset/processing/asset_processing.rs +++ b/examples/asset/processing/asset_processing.rs @@ -84,7 +84,7 @@ impl AssetLoader for TextLoader { reader: &'a mut Reader, settings: &'a TextSettings, _load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { let mut bytes = Vec::new(); reader.read_to_end(&mut bytes).await?; @@ -138,7 +138,7 @@ impl AssetLoader for CoolTextLoader { reader: &'a mut Reader, _settings: &'a Self::Settings, load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { let mut bytes = Vec::new(); reader.read_to_end(&mut bytes).await?; @@ -182,7 +182,7 @@ impl AssetSaver for CoolTextSaver { writer: &'a mut Writer, asset: SavedAsset<'a, Self::Asset>, settings: &'a Self::Settings, - ) -> BoxedFuture<'a, Result> { + ) -> BoxedFuture<'a, Result> { Box::pin(async move { let text = format!("{}{}", asset.text.clone(), settings.appended); writer.write_all(text.as_bytes()).await?;