From b50f2ec334672e7999376b68d3639b558e53ad12 Mon Sep 17 00:00:00 2001 From: Zachary Harrold Date: Thu, 10 Oct 2024 01:29:10 +1100 Subject: [PATCH] Remove `thiserror` from `bevy_scene` (#15764) # Objective - Contributes to #15460 ## Solution - Removed `thiserror` from `bevy_scene` --- crates/bevy_scene/Cargo.toml | 6 +++++- crates/bevy_scene/src/components.rs | 17 +++-------------- crates/bevy_scene/src/scene_loader.rs | 12 ++++++------ crates/bevy_scene/src/scene_spawner.rs | 20 ++++++++++---------- 4 files changed, 24 insertions(+), 31 deletions(-) diff --git a/crates/bevy_scene/Cargo.toml b/crates/bevy_scene/Cargo.toml index 8bdc32c215..9ad5df7339 100644 --- a/crates/bevy_scene/Cargo.toml +++ b/crates/bevy_scene/Cargo.toml @@ -29,7 +29,11 @@ bevy_render = { path = "../bevy_render", version = "0.15.0-dev", optional = true # other serde = { version = "1.0", features = ["derive"], optional = true } uuid = { version = "1.1", features = ["v4"] } -thiserror = "1.0" +derive_more = { version = "1", default-features = false, features = [ + "error", + "from", + "display", +] } [dev-dependencies] postcard = { version = "1.0", features = ["alloc"] } diff --git a/crates/bevy_scene/src/components.rs b/crates/bevy_scene/src/components.rs index 74f0f545d1..c1d70776e3 100644 --- a/crates/bevy_scene/src/components.rs +++ b/crates/bevy_scene/src/components.rs @@ -3,6 +3,7 @@ use bevy_derive::{Deref, DerefMut}; use bevy_ecs::component::Component; use bevy_reflect::Reflect; use bevy_transform::components::Transform; +use derive_more::derive::From; #[cfg(feature = "bevy_render")] use bevy_render::view::visibility::Visibility; @@ -11,26 +12,14 @@ use crate::{DynamicScene, Scene}; /// Adding this component will spawn the scene as a child of that entity. /// Once it's spawned, the entity will have a [`SceneInstance`](crate::SceneInstance) component. -#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq)] +#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq, From)] #[require(Transform)] #[cfg_attr(feature = "bevy_render", require(Visibility))] pub struct SceneRoot(pub Handle); -impl From> for SceneRoot { - fn from(handle: Handle) -> Self { - Self(handle) - } -} - /// Adding this component will spawn the scene as a child of that entity. /// Once it's spawned, the entity will have a [`SceneInstance`](crate::SceneInstance) component. -#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq)] +#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq, From)] #[require(Transform)] #[cfg_attr(feature = "bevy_render", require(Visibility))] pub struct DynamicSceneRoot(pub Handle); - -impl From> for DynamicSceneRoot { - fn from(handle: Handle) -> Self { - Self(handle) - } -} diff --git a/crates/bevy_scene/src/scene_loader.rs b/crates/bevy_scene/src/scene_loader.rs index 481b7ebc04..643ad7a516 100644 --- a/crates/bevy_scene/src/scene_loader.rs +++ b/crates/bevy_scene/src/scene_loader.rs @@ -7,9 +7,9 @@ use bevy_ecs::{ world::{FromWorld, World}, }; use bevy_reflect::TypeRegistryArc; +use derive_more::derive::{Display, Error, From}; #[cfg(feature = "serialize")] use serde::de::DeserializeSeed; -use thiserror::Error; /// Asset loader for a Bevy dynamic scene (`.scn` / `.scn.ron`). /// @@ -30,14 +30,14 @@ impl FromWorld for SceneLoader { /// Possible errors that can be produced by [`SceneLoader`] #[non_exhaustive] -#[derive(Debug, Error)] +#[derive(Debug, Error, Display, From)] pub enum SceneLoaderError { /// An [IO Error](std::io::Error) - #[error("Error while trying to read the scene file: {0}")] - Io(#[from] std::io::Error), + #[display("Error while trying to read the scene file: {_0}")] + Io(std::io::Error), /// A [RON Error](ron::error::SpannedError) - #[error("Could not parse RON: {0}")] - RonSpannedError(#[from] ron::error::SpannedError), + #[display("Could not parse RON: {_0}")] + RonSpannedError(ron::error::SpannedError), } #[cfg(feature = "serialize")] diff --git a/crates/bevy_scene/src/scene_spawner.rs b/crates/bevy_scene/src/scene_spawner.rs index 1fa42e6019..92c3e41571 100644 --- a/crates/bevy_scene/src/scene_spawner.rs +++ b/crates/bevy_scene/src/scene_spawner.rs @@ -8,8 +8,8 @@ use bevy_ecs::{ world::{Command, Mut, World}, }; use bevy_hierarchy::{AddChild, BuildChildren, DespawnRecursiveExt, Parent}; -use bevy_utils::{tracing::error, HashMap, HashSet}; -use thiserror::Error; +use bevy_utils::{HashMap, HashSet}; +use derive_more::derive::{Display, Error}; use uuid::Uuid; /// Triggered on a scene's parent entity when [`crate::SceneInstance`] becomes ready to use. @@ -72,22 +72,22 @@ pub struct SceneSpawner { } /// Errors that can occur when spawning a scene. -#[derive(Error, Debug)] +#[derive(Error, Display, Debug)] pub enum SceneSpawnError { /// Scene contains an unregistered component type. - #[error("scene contains the unregistered component `{type_path}`. consider adding `#[reflect(Component)]` to your type")] + #[display("scene contains the unregistered component `{type_path}`. consider adding `#[reflect(Component)]` to your type")] UnregisteredComponent { /// Type of the unregistered component. type_path: String, }, /// Scene contains an unregistered resource type. - #[error("scene contains the unregistered resource `{type_path}`. consider adding `#[reflect(Resource)]` to your type")] + #[display("scene contains the unregistered resource `{type_path}`. consider adding `#[reflect(Resource)]` to your type")] UnregisteredResource { /// Type of the unregistered resource. type_path: String, }, /// Scene contains an unregistered type. - #[error( + #[display( "scene contains the unregistered type `{std_type_name}`. \ consider reflecting it with `#[derive(Reflect)]` \ and registering the type using `app.register_type::()`" @@ -97,7 +97,7 @@ pub enum SceneSpawnError { std_type_name: String, }, /// Scene contains an unregistered type which has a `TypePath`. - #[error( + #[display( "scene contains the reflected type `{type_path}` but it was not found in the type registry. \ consider registering the type using `app.register_type::()``" )] @@ -106,19 +106,19 @@ pub enum SceneSpawnError { type_path: String, }, /// Scene contains a proxy without a represented type. - #[error("scene contains dynamic type `{type_path}` without a represented type. consider changing this using `set_represented_type`.")] + #[display("scene contains dynamic type `{type_path}` without a represented type. consider changing this using `set_represented_type`.")] NoRepresentedType { /// The dynamic instance type. type_path: String, }, /// Dynamic scene with the given id does not exist. - #[error("scene does not exist")] + #[display("scene does not exist")] NonExistentScene { /// Id of the non-existent dynamic scene. id: AssetId, }, /// Scene with the given id does not exist. - #[error("scene does not exist")] + #[display("scene does not exist")] NonExistentRealScene { /// Id of the non-existent scene. id: AssetId,