Skip to content

Commit c9e41ef

Browse files
authoredOct 9, 2024··
Remove thiserror from bevy_ui (#15760)
# Objective - Contributes to #15460 ## Solution - Removed `thiserror` from `bevy_ui`
1 parent bdc649a commit c9e41ef

File tree

5 files changed

+23
-28
lines changed

5 files changed

+23
-28
lines changed
 

‎crates/bevy_ui/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ bevy_utils = { path = "../bevy_utils", version = "0.15.0-dev" }
3636
taffy = { version = "0.5" }
3737
serde = { version = "1", features = ["derive"], optional = true }
3838
bytemuck = { version = "1.5", features = ["derive"] }
39-
thiserror = "1.0.0"
39+
derive_more = { version = "1", default-features = false, features = [
40+
"error",
41+
"from",
42+
"display",
43+
] }
4044
nonmax = "0.5"
4145
smallvec = "1.11"
4246

‎crates/bevy_ui/src/geometry.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bevy_math::Vec2;
22
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
33
use core::ops::{Div, DivAssign, Mul, MulAssign, Neg};
4-
use thiserror::Error;
4+
use derive_more::derive::{Display, Error};
55

66
#[cfg(feature = "serialize")]
77
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
@@ -175,11 +175,11 @@ impl Neg for Val {
175175
}
176176
}
177177

178-
#[derive(Debug, Eq, PartialEq, Clone, Copy, Error)]
178+
#[derive(Debug, Eq, PartialEq, Clone, Copy, Error, Display)]
179179
pub enum ValArithmeticError {
180-
#[error("the variants of the Vals don't match")]
180+
#[display("the variants of the Vals don't match")]
181181
NonIdenticalVariants,
182-
#[error("the given variant of Val is not evaluateable (non-numeric)")]
182+
#[display("the given variant of Val is not evaluateable (non-numeric)")]
183183
NonEvaluateable,
184184
}
185185

‎crates/bevy_ui/src/layout/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use bevy_sprite::BorderRect;
1818
use bevy_transform::components::Transform;
1919
use bevy_utils::tracing::warn;
2020
use bevy_window::{PrimaryWindow, Window, WindowScaleFactorChanged};
21-
use thiserror::Error;
21+
use derive_more::derive::{Display, Error, From};
2222
use ui_surface::UiSurface;
2323

2424
#[cfg(feature = "bevy_text")]
@@ -61,12 +61,12 @@ impl Default for LayoutContext {
6161
}
6262
}
6363

64-
#[derive(Debug, Error)]
64+
#[derive(Debug, Error, Display, From)]
6565
pub enum LayoutError {
66-
#[error("Invalid hierarchy")]
66+
#[display("Invalid hierarchy")]
6767
InvalidHierarchy,
68-
#[error("Taffy error: {0}")]
69-
TaffyError(#[from] taffy::TaffyError),
68+
#[display("Taffy error: {_0}")]
69+
TaffyError(taffy::TaffyError),
7070
}
7171

7272
#[doc(hidden)]

‎crates/bevy_ui/src/ui_material.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use bevy_render::{
88
extract_component::ExtractComponent,
99
render_resource::{AsBindGroup, RenderPipelineDescriptor, ShaderRef},
1010
};
11+
use derive_more::derive::From;
1112

1213
/// Materials are used alongside [`UiMaterialPlugin`](crate::UiMaterialPlugin) and [`MaterialNodeBundle`](crate::prelude::MaterialNodeBundle)
1314
/// to spawn entities that are rendered with a specific [`UiMaterial`] type. They serve as an easy to use high level
@@ -152,7 +153,9 @@ where
152153
}
153154
}
154155

155-
#[derive(Component, Clone, Debug, Deref, DerefMut, Reflect, PartialEq, Eq, ExtractComponent)]
156+
#[derive(
157+
Component, Clone, Debug, Deref, DerefMut, Reflect, PartialEq, Eq, ExtractComponent, From,
158+
)]
156159
#[reflect(Component, Default)]
157160
pub struct UiMaterialHandle<M: UiMaterial>(pub Handle<M>);
158161

@@ -162,12 +165,6 @@ impl<M: UiMaterial> Default for UiMaterialHandle<M> {
162165
}
163166
}
164167

165-
impl<M: UiMaterial> From<Handle<M>> for UiMaterialHandle<M> {
166-
fn from(handle: Handle<M>) -> Self {
167-
Self(handle)
168-
}
169-
}
170-
171168
impl<M: UiMaterial> From<UiMaterialHandle<M>> for AssetId<M> {
172169
fn from(material: UiMaterialHandle<M>) -> Self {
173170
material.id()

‎crates/bevy_ui/src/ui_node.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use bevy_sprite::BorderRect;
1212
use bevy_utils::warn_once;
1313
use bevy_window::{PrimaryWindow, WindowRef};
1414
use core::num::NonZero;
15+
use derive_more::derive::{Display, Error, From};
1516
use smallvec::SmallVec;
16-
use thiserror::Error;
1717

1818
/// Base component for a UI node, which also provides the computed size of the node.
1919
///
@@ -1333,7 +1333,7 @@ impl Default for GridTrack {
13331333
}
13341334
}
13351335

1336-
#[derive(Copy, Clone, PartialEq, Debug, Reflect)]
1336+
#[derive(Copy, Clone, PartialEq, Debug, Reflect, From)]
13371337
#[reflect(Default, PartialEq)]
13381338
#[cfg_attr(
13391339
feature = "serialize",
@@ -1363,12 +1363,6 @@ impl Default for GridTrackRepetition {
13631363
}
13641364
}
13651365

1366-
impl From<u16> for GridTrackRepetition {
1367-
fn from(count: u16) -> Self {
1368-
Self::Count(count)
1369-
}
1370-
}
1371-
13721366
impl From<i32> for GridTrackRepetition {
13731367
fn from(count: i32) -> Self {
13741368
Self::Count(count as u16)
@@ -1784,11 +1778,11 @@ fn try_into_grid_span(span: u16) -> Result<Option<NonZero<u16>>, GridPlacementEr
17841778
}
17851779

17861780
/// Errors that occur when setting constraints for a `GridPlacement`
1787-
#[derive(Debug, Eq, PartialEq, Clone, Copy, Error)]
1781+
#[derive(Debug, Eq, PartialEq, Clone, Copy, Error, Display)]
17881782
pub enum GridPlacementError {
1789-
#[error("Zero is not a valid grid position")]
1783+
#[display("Zero is not a valid grid position")]
17901784
InvalidZeroIndex,
1791-
#[error("Spans cannot be zero length")]
1785+
#[display("Spans cannot be zero length")]
17921786
InvalidZeroSpan,
17931787
}
17941788

0 commit comments

Comments
 (0)
Please sign in to comment.