Skip to content

Commit 4e0dbf6

Browse files
committed
add optional serde feature to serialize/deserialize
1 parent 61582f5 commit 4e0dbf6

File tree

11 files changed

+19
-1
lines changed

11 files changed

+19
-1
lines changed

.github/workflows/CI.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,34 @@ env:
1010

1111
jobs:
1212
build:
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
features: ['', '--features rgb,serde']
1317

1418
runs-on: ubuntu-latest
15-
1619
steps:
1720
- uses: actions/checkout@v3
1821
- uses: actions-rs/cargo@v1
1922
with:
2023
command: build
24+
args: ${{ matrix.features }}
2125
- uses: actions-rs/cargo@v1
2226
with:
2327
command: check
28+
args: ${{ matrix.features }}
2429
- uses: actions-rs/cargo@v1
2530
with:
2631
command: test
32+
args: ${{ matrix.features }}
2733
- uses: actions-rs/cargo@v1
2834
with:
2935
command: fmt
3036
args: --all -- --check
3137
- uses: actions-rs/cargo@v1
3238
with:
3339
command: clippy
40+
args: ${{ matrix.features }}
3441
- uses: actions-rs/cargo@v1
3542
with:
3643
command: audit

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ license = "MIT OR Apache-2.0"
1111
[dependencies]
1212
defmt = { version = "0.3", optional = true }
1313
heapless = { version = "0.7" }
14+
1415
rgb = { version = "0.8", optional = true }
16+
serde = { version = "1.0", features = ["derive"], optional = true }
1517

1618
[features]
1719
default = ["accelerometer_event", "button_event", "color_event", "gyro_event", "location_event", "magnetometer_event", "quaternion_event"]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Note that this work is not affiliated with Adafruit.
1212
## Optional features
1313
* `defmt`: you can enable the [`defmt`](https://defmt.ferrous-systems.com/) feature to get a `defmt::Format` implementation for all structs & enums and a `defmt::debug!` call for each command being parsed.
1414
* `rgb`: if enabled, the `ColorEvent` implements `Into<RGB8>` for the [RGB crate](https://crates.io/crates/rgb).
15+
* `serde`: if enabled, all events implement the [serde](https://serde.rs/) `#[derive(Serialize, Deserialize)]`.
1516
* All events can be selected as individual features. By default, they are all selected,
1617
but you can opt to only select the event(s) you are interested in which will result in a small binary size.
1718
If other events are received, a `ProtocolParseError::DisabledControllerDataPackageType` will be returned.

src/accelerometer_event.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use super::{try_f32_from_le_bytes, ProtocolParseError};
55
/// Represents an accelerometer event from the protocol.
66
#[derive(PartialEq, Debug)]
77
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
8+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
89
#[allow(missing_docs)] // the names are already obvious enough
910
pub struct AccelerometerEvent {
1011
x: f32,

src/button_event.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ impl Button {
4747
/// The state of the button.
4848
#[derive(PartialEq, Eq, Debug)]
4949
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
50+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5051
#[allow(missing_docs)] // the names are already obvious enough
5152
pub enum ButtonState {
5253
Released,

src/color_event.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rgb::RGB8;
77
/// Represents a color event from the protocol.
88
#[derive(PartialEq, Eq, Debug)]
99
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
10+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1011
#[allow(missing_docs)] // the names are already obvious enough
1112
pub struct ColorEvent {
1213
red: u8,

src/gyro_event.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use super::{try_f32_from_le_bytes, ProtocolParseError};
55
/// Represents a gyro event from the protocol.
66
#[derive(PartialEq, Debug)]
77
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
8+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
89
#[allow(missing_docs)] // the names are already obvious enough
910
pub struct GyroEvent {
1011
x: f32,

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! ## Optional features
55
//! * `defmt`: you can enable the `defmt` feature to get a `defmt::Format` implementation for all structs & enums and a `defmt::debug!` call for each command being parsed.
66
//! * `rgb`: if enabled, the `ColorEvent` implements `Into<RGB8>` for the [RGB crate](https://crates.io/crates/rgb).
7+
//! * `serde`: if enabled, all events implement the [serde](https://serde.rs/) `#[derive(Serialize, Deserialize)]`.
78
//! * All events can be selected as individual features. By default, they are all selected,
89
//! but you can opt to only select the event(s) you are interested in which will result in a small binary size.
910
//! If other events are received, a [`ProtocolParseError::DisabledControllerDataPackageType`] will be returned.

src/location_event.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use super::{try_f32_from_le_bytes, ProtocolParseError};
55
/// Represents a location event from the protocol.
66
#[derive(PartialEq, Debug)]
77
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
8+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
89
#[allow(missing_docs)] // the names are already obvious enough
910
pub struct LocationEvent {
1011
latitude: f32,

src/magnetometer_event.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use super::{try_f32_from_le_bytes, ProtocolParseError};
55
/// Represents a magnetometer event from the protocol.
66
#[derive(PartialEq, Debug)]
77
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
8+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
89
#[allow(missing_docs)] // the names are already obvious enough
910
pub struct MagnetometerEvent {
1011
x: f32,

0 commit comments

Comments
 (0)