Skip to content

Commit

Permalink
Export anyhow::error for custom asset loaders (bevyengine#5359)
Browse files Browse the repository at this point in the history
If users try to implement a custom asset loader, they must manually import anyhow::error as it's used by the asset loader trait but not exported.

https://github.com/bevyengine/bevy/blob/2b93ab58128178fef64de8134a130f036f07dc5d/examples/asset/custom_asset.rs#L25

Fixes bevyengine#3138

Co-authored-by: sark <[email protected]>
  • Loading branch information
2 people authored and ItsDoot committed Feb 1, 2023
1 parent 4869e48 commit 485234b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub mod prelude {
pub use crate::{AddAsset, AssetEvent, AssetServer, Assets, Handle, HandleUntyped};
}

pub use anyhow::Error;
pub use asset_server::*;
pub use assets::*;
pub use bevy_utils::BoxedFuture;
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_asset/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
path::AssetPath, AssetIo, AssetIoError, AssetMeta, AssetServer, Assets, Handle, HandleId,
RefChangeChannel,
};
use anyhow::Error;
use anyhow::Result;
use bevy_ecs::system::{Res, ResMut};
use bevy_reflect::{TypeUuid, TypeUuidDynamic};
Expand All @@ -20,7 +21,7 @@ pub trait AssetLoader: Send + Sync + 'static {
&'a self,
bytes: &'a [u8],
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<(), anyhow::Error>>;
) -> BoxedFuture<'a, Result<(), Error>>;

/// Returns a list of extensions supported by this asset loader, without the preceding dot.
fn extensions(&self) -> &[&str];
Expand Down
2 changes: 1 addition & 1 deletion examples/asset/custom_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl AssetLoader for CustomAssetLoader {
&'a self,
bytes: &'a [u8],
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<(), anyhow::Error>> {
) -> BoxedFuture<'a, Result<(), bevy::asset::Error>> {
Box::pin(async move {
let custom_asset = ron::de::from_bytes::<CustomAsset>(bytes)?;
load_context.set_default_asset(LoadedAsset::new(custom_asset));
Expand Down

0 comments on commit 485234b

Please sign in to comment.