Skip to content

Commit 29cca90

Browse files
committed
add Copy, Clone and Hash on error & event types
note that `Hash` cannot be added to types which use floats underneath. for the same reason `Eq` cannot be added (but `PartialEq` is present). this resolves [C-COMMON-TRAITS] of the API guidelines. [C-COMMON-TRAITS]: https://rust-lang.github.io/api-guidelines/interoperability.html#c-common-traits
1 parent 4dab854 commit 29cca90

9 files changed

+15
-13
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
<!-- next-header -->
88
## [Unreleased] - ReleaseDate
9+
### Added
10+
* `Copy`, `Clone` and `Hash` on error & event types (where possible)
911
### Changed
1012
* The MSRV has been updated to 1.81.0 due to `core::error::Error` being implemented
1113
* **BREAKING**: the features `use_alloc` and `use_heapless` have been renamed to `alloc` and `heapless` respectively.

src/accelerometer_event.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use super::{try_f32_from_le_bytes, ProtocolParseError};
44

55
/// Represents an accelerometer event from the protocol.
6-
#[derive(PartialEq, Debug)]
6+
#[derive(PartialEq, Debug, Copy, Clone)]
77
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
88
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
99
#[allow(missing_docs)] // the names are already obvious enough

src/button_event.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::error::Error;
55
use core::fmt::{Display, Formatter};
66

77
/// Errors which can be raised while parsing a button event.
8-
#[derive(PartialEq, Eq, Debug)]
8+
#[derive(PartialEq, Eq, Debug, Hash, Clone, Copy)]
99
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1010
pub enum ButtonParseError {
1111
/// The message contained an unknown button. For the known buttons see [`Button`].
@@ -27,7 +27,7 @@ impl Display for ButtonParseError {
2727
impl Error for ButtonParseError {}
2828

2929
/// Lists all possible buttons which can be sent in the event.
30-
#[derive(PartialEq, Eq, Debug)]
30+
#[derive(PartialEq, Eq, Debug, Copy, Clone, Hash)]
3131
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
3232
#[allow(missing_docs)] // the names are already obvious enough
3333
pub enum Button {
@@ -59,7 +59,7 @@ impl Button {
5959
}
6060

6161
/// The state of the button.
62-
#[derive(PartialEq, Eq, Debug)]
62+
#[derive(PartialEq, Eq, Debug, Copy, Clone, Hash)]
6363
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
6464
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6565
#[allow(missing_docs)] // the names are already obvious enough
@@ -80,7 +80,7 @@ impl ButtonState {
8080
}
8181

8282
/// Represents a button event from the protocol.
83-
#[derive(PartialEq, Eq, Debug)]
83+
#[derive(PartialEq, Eq, Debug, Copy, Clone, Hash)]
8484
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
8585
#[allow(missing_docs)] // the names are already obvious enough
8686
pub struct ButtonEvent {

src/color_event.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use super::ProtocolParseError;
55
use rgb::RGB8;
66

77
/// Represents a color event from the protocol.
8-
#[derive(PartialEq, Eq, Debug)]
8+
#[derive(PartialEq, Eq, Debug, Copy, Clone, Hash)]
99
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1010
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1111
#[allow(missing_docs)] // the names are already obvious enough

src/gyro_event.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use super::{try_f32_from_le_bytes, ProtocolParseError};
44

55
/// Represents a gyro event from the protocol.
6-
#[derive(PartialEq, Debug)]
6+
#[derive(PartialEq, Debug, Copy, Clone)]
77
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
88
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
99
#[allow(missing_docs)] // the names are already obvious enough

src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ use magnetometer_event::MagnetometerEvent;
7676
use quaternion_event::QuaternionEvent;
7777

7878
/// Lists all (supported) events which can be sent by the controller. These come with the parsed event data and are the result of a [`parse`] call.
79-
#[derive(PartialEq, Debug)]
79+
#[derive(PartialEq, Debug, Copy, Clone)]
8080
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
8181
#[allow(missing_docs)] // the names are already obvious enough
8282
pub enum ControllerEvent {
@@ -97,7 +97,7 @@ pub enum ControllerEvent {
9797
}
9898

9999
/// Represents the different kinds of errors which can happen when the protocol is being parsed.
100-
#[derive(PartialEq, Eq, Debug)]
100+
#[derive(PartialEq, Eq, Debug, Copy, Clone, Hash)]
101101
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
102102
pub enum ProtocolParseError {
103103
/// The message contained an event which is not known to the current implementation.
@@ -157,7 +157,7 @@ impl Error for ProtocolParseError {
157157
}
158158

159159
/// Lists all data packages which can be sent by the controller. Internal state used during parsing. Use [`ControllerEvent`] to return the actual event.
160-
#[derive(PartialEq, Eq, Debug)]
160+
#[derive(PartialEq, Eq, Debug, Hash, Clone, Copy)]
161161
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
162162
#[allow(missing_docs)] // the names are already obvious enough
163163
pub enum ControllerDataPackageType {

src/location_event.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use super::{try_f32_from_le_bytes, ProtocolParseError};
44

55
/// Represents a location event from the protocol.
6-
#[derive(PartialEq, Debug)]
6+
#[derive(PartialEq, Debug, Copy, Clone)]
77
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
88
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
99
#[allow(missing_docs)] // the names are already obvious enough

src/magnetometer_event.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use super::{try_f32_from_le_bytes, ProtocolParseError};
44

55
/// Represents a magnetometer event from the protocol.
6-
#[derive(PartialEq, Debug)]
6+
#[derive(PartialEq, Debug, Copy, Clone)]
77
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
88
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
99
#[allow(missing_docs)] // the names are already obvious enough

src/quaternion_event.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use super::{try_f32_from_le_bytes, ProtocolParseError};
44

55
/// Represents a [quaternion](https://en.wikipedia.org/wiki/Quaternion) event from the protocol.
6-
#[derive(PartialEq, Debug)]
6+
#[derive(PartialEq, Debug, Copy, Clone)]
77
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
88
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
99
#[allow(missing_docs)] // the names are already obvious enough

0 commit comments

Comments
 (0)