From 814f8ec039b7d0464e41f62b2e48d770b2bd641b Mon Sep 17 00:00:00 2001 From: Zachary Harrold Date: Thu, 10 Oct 2024 01:16:21 +1100 Subject: [PATCH] Remove `thiserror` from `bevy_animation` (#15780) # Objective - Contributes to #15460 ## Solution - Removed `thiserror` from `bevy_animation` --- crates/bevy_animation/Cargo.toml | 6 +++++- crates/bevy_animation/src/gltf_curves.rs | 11 +++++------ crates/bevy_animation/src/graph.rs | 24 +++++++++--------------- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/crates/bevy_animation/Cargo.toml b/crates/bevy_animation/Cargo.toml index faef0cdbb2daf..1614d98f54980 100644 --- a/crates/bevy_animation/Cargo.toml +++ b/crates/bevy_animation/Cargo.toml @@ -34,7 +34,11 @@ petgraph = { version = "0.6", features = ["serde-1"] } ron = "0.8" serde = "1" blake3 = { version = "1.0" } -thiserror = "1" +derive_more = { version = "1", default-features = false, features = [ + "error", + "from", + "display", +] } thread_local = "1" uuid = { version = "1.7", features = ["v4"] } smallvec = "1" diff --git a/crates/bevy_animation/src/gltf_curves.rs b/crates/bevy_animation/src/gltf_curves.rs index 60367967a2d5a..74d86fd03baf8 100644 --- a/crates/bevy_animation/src/gltf_curves.rs +++ b/crates/bevy_animation/src/gltf_curves.rs @@ -5,7 +5,7 @@ use bevy_math::{ vec4, Quat, Vec4, VectorSpace, }; use bevy_reflect::Reflect; -use thiserror::Error; +use derive_more::derive::{Display, Error, From}; /// A keyframe-defined curve that "interpolates" by stepping at `t = 1.0` to the next keyframe. #[derive(Debug, Clone, Reflect)] @@ -318,20 +318,19 @@ where } /// An error indicating that a multisampling keyframe curve could not be constructed. -#[derive(Debug, Error)] -#[error("unable to construct a curve using this data")] +#[derive(Debug, Error, Display, From)] +#[display("unable to construct a curve using this data")] pub enum WideKeyframeCurveError { /// The number of given values was not divisible by a multiple of the number of keyframes. - #[error("number of values ({values_given}) is not divisible by {divisor}")] + #[display("number of values ({values_given}) is not divisible by {divisor}")] LengthMismatch { /// The number of values given. values_given: usize, /// The number that `values_given` was supposed to be divisible by. divisor: usize, }, - /// An error was returned by the internal core constructor. - CoreError(#[from] ChunkedUnevenCoreError), + CoreError(ChunkedUnevenCoreError), } impl WideCubicKeyframeCurve { diff --git a/crates/bevy_animation/src/graph.rs b/crates/bevy_animation/src/graph.rs index aca3220855908..45144aa4cd1cd 100644 --- a/crates/bevy_animation/src/graph.rs +++ b/crates/bevy_animation/src/graph.rs @@ -16,6 +16,7 @@ use bevy_ecs::{ }; use bevy_reflect::{prelude::ReflectDefault, Reflect, ReflectSerialize}; use bevy_utils::HashMap; +use derive_more::derive::{Display, Error, From}; use petgraph::{ graph::{DiGraph, NodeIndex}, Direction, @@ -23,7 +24,6 @@ use petgraph::{ use ron::de::SpannedError; use serde::{Deserialize, Serialize}; use smallvec::SmallVec; -use thiserror::Error; use crate::{AnimationClip, AnimationTargetId}; @@ -126,16 +126,10 @@ pub struct AnimationGraph { } /// A [`Handle`] to the [`AnimationGraph`] to be used by the [`AnimationPlayer`](crate::AnimationPlayer) on the same entity. -#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq)] +#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq, From)] #[reflect(Component, Default)] pub struct AnimationGraphHandle(pub Handle); -impl From> for AnimationGraphHandle { - fn from(handle: Handle) -> Self { - Self(handle) - } -} - impl From for AssetId { fn from(handle: AnimationGraphHandle) -> Self { handle.id() @@ -230,18 +224,18 @@ pub struct AnimationGraphAssetLoader; /// Various errors that can occur when serializing or deserializing animation /// graphs to and from RON, respectively. -#[derive(Error, Debug)] +#[derive(Error, Display, Debug, From)] pub enum AnimationGraphLoadError { /// An I/O error occurred. - #[error("I/O")] - Io(#[from] io::Error), + #[display("I/O")] + Io(io::Error), /// An error occurred in RON serialization or deserialization. - #[error("RON serialization")] - Ron(#[from] ron::Error), + #[display("RON serialization")] + Ron(ron::Error), /// An error occurred in RON deserialization, and the location of the error /// is supplied. - #[error("RON serialization")] - SpannedRon(#[from] SpannedError), + #[display("RON serialization")] + SpannedRon(SpannedError), } /// Acceleration structures for animation graphs that allows Bevy to evaluate