Skip to content

Commit 941a687

Browse files
committed
add optional Into<RGB8> for ColorEvent
1 parent 63d72a8 commit 941a687

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ license = "MIT"
1111
[dependencies]
1212
defmt = { version = "0.3", optional = true }
1313
heapless = { version = "0.7" }
14+
rgb = { version = "0.8", optional = true }
1415

1516
[features]
1617
defmt = ["dep:defmt", "heapless/defmt-impl"]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Note that this work is not affiliated with Adafruit.
88

99
## Optional features
1010
* `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.
11+
* `rgb`: if enabled, the `ColorEvent` implements `Into<RGB8>` for the [RGB crate](https://crates.io/crates/rgb).

src/color_event.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Implements the [`ColorEvent`] and its parsing from the protocol.
22
33
use super::ProtocolParseError;
4+
#[cfg(feature = "rgb")]
5+
use rgb::RGB8;
46

57
/// Represents a color event from the protocol.
68
#[derive(PartialEq, Eq, Debug)]
@@ -46,3 +48,14 @@ impl ColorEvent {
4648
self.blue
4749
}
4850
}
51+
52+
#[cfg(feature = "rgb")]
53+
impl Into<RGB8> for ColorEvent {
54+
fn into(self) -> RGB8 {
55+
RGB8 {
56+
r: self.red,
57+
g: self.green,
58+
b: self.blue,
59+
}
60+
}
61+
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//!
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.
6+
//! * `rgb`: if enabled, the `ColorEvent` implements `Into<RGB8>` for the [RGB crate](https://crates.io/crates/rgb).
67
78
#![forbid(unsafe_code)]
89
// use deny instead of forbid due to bogus warnings, see also https://github.com/rust-lang/rust/issues/81670

0 commit comments

Comments
 (0)