Skip to content

Commit 5e89aca

Browse files
Remove thiserror from bevy_input (#15770)
# Objective - Contributes to #15460 ## Solution - Removed `thiserror` from `bevy_input`
1 parent f88c682 commit 5e89aca

File tree

2 files changed

+28
-65
lines changed

2 files changed

+28
-65
lines changed

crates/bevy_input/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.15.0-dev", features = [
3636

3737
# other
3838
serde = { version = "1", features = ["derive"], optional = true }
39-
thiserror = "1.0"
39+
derive_more = { version = "1", default-features = false, features = [
40+
"error",
41+
"from",
42+
"display",
43+
] }
4044
smol_str = "0.2"
4145

4246
[lints]

crates/bevy_input/src/gamepad.rs

Lines changed: 23 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use bevy_utils::{
1717
tracing::{info, warn},
1818
Duration, HashMap,
1919
};
20-
use thiserror::Error;
20+
use derive_more::derive::{Display, Error, From};
2121

2222
/// A gamepad event.
2323
///
@@ -26,7 +26,7 @@ use thiserror::Error;
2626
/// the in-frame relative ordering of events is important.
2727
///
2828
/// This event is produced by `bevy_input`
29-
#[derive(Event, Debug, Clone, PartialEq)]
29+
#[derive(Event, Debug, Clone, PartialEq, From)]
3030
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))]
3131
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
3232
#[cfg_attr(
@@ -42,32 +42,14 @@ pub enum GamepadEvent {
4242
Axis(GamepadAxisChangedEvent),
4343
}
4444

45-
impl From<GamepadConnectionEvent> for GamepadEvent {
46-
fn from(value: GamepadConnectionEvent) -> Self {
47-
Self::Connection(value)
48-
}
49-
}
50-
51-
impl From<GamepadButtonChangedEvent> for GamepadEvent {
52-
fn from(value: GamepadButtonChangedEvent) -> Self {
53-
Self::Button(value)
54-
}
55-
}
56-
57-
impl From<GamepadAxisChangedEvent> for GamepadEvent {
58-
fn from(value: GamepadAxisChangedEvent) -> Self {
59-
Self::Axis(value)
60-
}
61-
}
62-
6345
/// A raw gamepad event.
6446
///
6547
/// This event type is used over the [`GamepadConnectionEvent`],
6648
/// [`RawGamepadButtonChangedEvent`] and [`RawGamepadAxisChangedEvent`] when
6749
/// the in-frame relative ordering of events is important.
6850
///
6951
/// This event type is used by `bevy_input` to feed its components.
70-
#[derive(Event, Debug, Clone, PartialEq, Reflect)]
52+
#[derive(Event, Debug, Clone, PartialEq, Reflect, From)]
7153
#[reflect(Debug, PartialEq)]
7254
#[cfg_attr(
7355
feature = "serialize",
@@ -83,24 +65,6 @@ pub enum RawGamepadEvent {
8365
Axis(RawGamepadAxisChangedEvent),
8466
}
8567

86-
impl From<GamepadConnectionEvent> for RawGamepadEvent {
87-
fn from(value: GamepadConnectionEvent) -> Self {
88-
Self::Connection(value)
89-
}
90-
}
91-
92-
impl From<RawGamepadButtonChangedEvent> for RawGamepadEvent {
93-
fn from(value: RawGamepadButtonChangedEvent) -> Self {
94-
Self::Button(value)
95-
}
96-
}
97-
98-
impl From<RawGamepadAxisChangedEvent> for RawGamepadEvent {
99-
fn from(value: RawGamepadAxisChangedEvent) -> Self {
100-
Self::Axis(value)
101-
}
102-
}
103-
10468
/// [`GamepadButton`] changed event unfiltered by [`GamepadSettings`]
10569
#[derive(Event, Debug, Copy, Clone, PartialEq, Reflect)]
10670
#[reflect(Debug, PartialEq)]
@@ -281,52 +245,59 @@ impl GamepadAxisChangedEvent {
281245
}
282246

283247
/// Errors that occur when setting axis settings for gamepad input.
284-
#[derive(Error, Debug, PartialEq)]
248+
#[derive(Error, Display, Debug, PartialEq)]
285249
pub enum AxisSettingsError {
286250
/// The given parameter `livezone_lowerbound` was not in range -1.0..=0.0.
287-
#[error("invalid livezone_lowerbound {0}, expected value [-1.0..=0.0]")]
251+
#[display("invalid livezone_lowerbound {_0}, expected value [-1.0..=0.0]")]
252+
#[error(ignore)]
288253
LiveZoneLowerBoundOutOfRange(f32),
289254
/// The given parameter `deadzone_lowerbound` was not in range -1.0..=0.0.
290-
#[error("invalid deadzone_lowerbound {0}, expected value [-1.0..=0.0]")]
255+
#[display("invalid deadzone_lowerbound {_0}, expected value [-1.0..=0.0]")]
256+
#[error(ignore)]
291257
DeadZoneLowerBoundOutOfRange(f32),
292258
/// The given parameter `deadzone_lowerbound` was not in range -1.0..=0.0.
293-
#[error("invalid deadzone_upperbound {0}, expected value [0.0..=1.0]")]
259+
#[display("invalid deadzone_upperbound {_0}, expected value [0.0..=1.0]")]
260+
#[error(ignore)]
294261
DeadZoneUpperBoundOutOfRange(f32),
295262
/// The given parameter `deadzone_lowerbound` was not in range -1.0..=0.0.
296-
#[error("invalid livezone_upperbound {0}, expected value [0.0..=1.0]")]
263+
#[display("invalid livezone_upperbound {_0}, expected value [0.0..=1.0]")]
264+
#[error(ignore)]
297265
LiveZoneUpperBoundOutOfRange(f32),
298266
/// Parameter `livezone_lowerbound` was not less than or equal to parameter `deadzone_lowerbound`.
299-
#[error("invalid parameter values livezone_lowerbound {} deadzone_lowerbound {}, expected livezone_lowerbound <= deadzone_lowerbound", .livezone_lowerbound, .deadzone_lowerbound)]
267+
#[display("invalid parameter values livezone_lowerbound {} deadzone_lowerbound {}, expected livezone_lowerbound <= deadzone_lowerbound", livezone_lowerbound, deadzone_lowerbound)]
300268
LiveZoneLowerBoundGreaterThanDeadZoneLowerBound {
301269
/// The value of the `livezone_lowerbound` parameter.
302270
livezone_lowerbound: f32,
303271
/// The value of the `deadzone_lowerbound` parameter.
304272
deadzone_lowerbound: f32,
305273
},
306274
/// Parameter `deadzone_upperbound` was not less than or equal to parameter `livezone_upperbound`.
307-
#[error("invalid parameter values livezone_upperbound {} deadzone_upperbound {}, expected deadzone_upperbound <= livezone_upperbound", .livezone_upperbound, .deadzone_upperbound)]
275+
#[display("invalid parameter values livezone_upperbound {} deadzone_upperbound {}, expected deadzone_upperbound <= livezone_upperbound", livezone_upperbound, deadzone_upperbound)]
308276
DeadZoneUpperBoundGreaterThanLiveZoneUpperBound {
309277
/// The value of the `livezone_upperbound` parameter.
310278
livezone_upperbound: f32,
311279
/// The value of the `deadzone_upperbound` parameter.
312280
deadzone_upperbound: f32,
313281
},
314282
/// The given parameter was not in range 0.0..=2.0.
315-
#[error("invalid threshold {0}, expected 0.0 <= threshold <= 2.0")]
283+
#[display("invalid threshold {_0}, expected 0.0 <= threshold <= 2.0")]
284+
#[error(ignore)]
316285
Threshold(f32),
317286
}
318287

319288
/// Errors that occur when setting button settings for gamepad input.
320-
#[derive(Error, Debug, PartialEq)]
289+
#[derive(Error, Display, Debug, PartialEq)]
321290
pub enum ButtonSettingsError {
322291
/// The given parameter was not in range 0.0..=1.0.
323-
#[error("invalid release_threshold {0}, expected value [0.0..=1.0]")]
292+
#[display("invalid release_threshold {_0}, expected value [0.0..=1.0]")]
293+
#[error(ignore)]
324294
ReleaseThresholdOutOfRange(f32),
325295
/// The given parameter was not in range 0.0..=1.0.
326-
#[error("invalid press_threshold {0}, expected [0.0..=1.0]")]
296+
#[display("invalid press_threshold {_0}, expected [0.0..=1.0]")]
297+
#[error(ignore)]
327298
PressThresholdOutOfRange(f32),
328299
/// Parameter `release_threshold` was not less than or equal to `press_threshold`.
329-
#[error("invalid parameter values release_threshold {} press_threshold {}, expected release_threshold <= press_threshold", .release_threshold, .press_threshold)]
300+
#[display("invalid parameter values release_threshold {} press_threshold {}, expected release_threshold <= press_threshold", release_threshold, press_threshold)]
330301
ReleaseThresholdGreaterThanPressThreshold {
331302
/// The value of the `press_threshold` parameter.
332303
press_threshold: f32,
@@ -716,7 +687,7 @@ impl GamepadAxis {
716687

717688
/// Encapsulation over [`GamepadAxis`] and [`GamepadButton`]
718689
// This is done so Gamepad can share a single Axis<T> and simplifies the API by having only one get/get_unclamped method
719-
#[derive(Debug, Copy, Clone, Eq, Hash, PartialEq)]
690+
#[derive(Debug, Copy, Clone, Eq, Hash, PartialEq, From)]
720691
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))]
721692
pub enum GamepadInput {
722693
/// A [`GamepadAxis`]
@@ -725,18 +696,6 @@ pub enum GamepadInput {
725696
Button(GamepadButton),
726697
}
727698

728-
impl From<GamepadAxis> for GamepadInput {
729-
fn from(value: GamepadAxis) -> Self {
730-
GamepadInput::Axis(value)
731-
}
732-
}
733-
734-
impl From<GamepadButton> for GamepadInput {
735-
fn from(value: GamepadButton) -> Self {
736-
GamepadInput::Button(value)
737-
}
738-
}
739-
740699
/// Gamepad settings component.
741700
///
742701
/// ## Usage

0 commit comments

Comments
 (0)