Skip to content

Commit

Permalink
Remove thiserror from bevy_ui (#15760)
Browse files Browse the repository at this point in the history
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_ui`
  • Loading branch information
bushrat011899 authored Oct 9, 2024
1 parent bdc649a commit c9e41ef
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 28 deletions.
6 changes: 5 additions & 1 deletion crates/bevy_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ bevy_utils = { path = "../bevy_utils", version = "0.15.0-dev" }
taffy = { version = "0.5" }
serde = { version = "1", features = ["derive"], optional = true }
bytemuck = { version = "1.5", features = ["derive"] }
thiserror = "1.0.0"
derive_more = { version = "1", default-features = false, features = [
"error",
"from",
"display",
] }
nonmax = "0.5"
smallvec = "1.11"

Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_ui/src/geometry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy_math::Vec2;
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use core::ops::{Div, DivAssign, Mul, MulAssign, Neg};
use thiserror::Error;
use derive_more::derive::{Display, Error};

#[cfg(feature = "serialize")]
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
Expand Down Expand Up @@ -175,11 +175,11 @@ impl Neg for Val {
}
}

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

Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_ui/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use bevy_sprite::BorderRect;
use bevy_transform::components::Transform;
use bevy_utils::tracing::warn;
use bevy_window::{PrimaryWindow, Window, WindowScaleFactorChanged};
use thiserror::Error;
use derive_more::derive::{Display, Error, From};
use ui_surface::UiSurface;

#[cfg(feature = "bevy_text")]
Expand Down Expand Up @@ -61,12 +61,12 @@ impl Default for LayoutContext {
}
}

#[derive(Debug, Error)]
#[derive(Debug, Error, Display, From)]
pub enum LayoutError {
#[error("Invalid hierarchy")]
#[display("Invalid hierarchy")]
InvalidHierarchy,
#[error("Taffy error: {0}")]
TaffyError(#[from] taffy::TaffyError),
#[display("Taffy error: {_0}")]
TaffyError(taffy::TaffyError),
}

#[doc(hidden)]
Expand Down
11 changes: 4 additions & 7 deletions crates/bevy_ui/src/ui_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use bevy_render::{
extract_component::ExtractComponent,
render_resource::{AsBindGroup, RenderPipelineDescriptor, ShaderRef},
};
use derive_more::derive::From;

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

#[derive(Component, Clone, Debug, Deref, DerefMut, Reflect, PartialEq, Eq, ExtractComponent)]
#[derive(
Component, Clone, Debug, Deref, DerefMut, Reflect, PartialEq, Eq, ExtractComponent, From,
)]
#[reflect(Component, Default)]
pub struct UiMaterialHandle<M: UiMaterial>(pub Handle<M>);

Expand All @@ -162,12 +165,6 @@ impl<M: UiMaterial> Default for UiMaterialHandle<M> {
}
}

impl<M: UiMaterial> From<Handle<M>> for UiMaterialHandle<M> {
fn from(handle: Handle<M>) -> Self {
Self(handle)
}
}

impl<M: UiMaterial> From<UiMaterialHandle<M>> for AssetId<M> {
fn from(material: UiMaterialHandle<M>) -> Self {
material.id()
Expand Down
16 changes: 5 additions & 11 deletions crates/bevy_ui/src/ui_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use bevy_sprite::BorderRect;
use bevy_utils::warn_once;
use bevy_window::{PrimaryWindow, WindowRef};
use core::num::NonZero;
use derive_more::derive::{Display, Error, From};
use smallvec::SmallVec;
use thiserror::Error;

/// Base component for a UI node, which also provides the computed size of the node.
///
Expand Down Expand Up @@ -1333,7 +1333,7 @@ impl Default for GridTrack {
}
}

#[derive(Copy, Clone, PartialEq, Debug, Reflect)]
#[derive(Copy, Clone, PartialEq, Debug, Reflect, From)]
#[reflect(Default, PartialEq)]
#[cfg_attr(
feature = "serialize",
Expand Down Expand Up @@ -1363,12 +1363,6 @@ impl Default for GridTrackRepetition {
}
}

impl From<u16> for GridTrackRepetition {
fn from(count: u16) -> Self {
Self::Count(count)
}
}

impl From<i32> for GridTrackRepetition {
fn from(count: i32) -> Self {
Self::Count(count as u16)
Expand Down Expand Up @@ -1784,11 +1778,11 @@ fn try_into_grid_span(span: u16) -> Result<Option<NonZero<u16>>, GridPlacementEr
}

/// Errors that occur when setting constraints for a `GridPlacement`
#[derive(Debug, Eq, PartialEq, Clone, Copy, Error)]
#[derive(Debug, Eq, PartialEq, Clone, Copy, Error, Display)]
pub enum GridPlacementError {
#[error("Zero is not a valid grid position")]
#[display("Zero is not a valid grid position")]
InvalidZeroIndex,
#[error("Spans cannot be zero length")]
#[display("Spans cannot be zero length")]
InvalidZeroSpan,
}

Expand Down

0 comments on commit c9e41ef

Please sign in to comment.