Skip to content

Commit 5113365

Browse files
committed
add missing docs & additional forbid/deny restrictions
1 parent c996d03 commit 5113365

File tree

8 files changed

+37
-6
lines changed

8 files changed

+37
-6
lines changed

src/accelerometer_event.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use super::{try_f32_from_le_bytes, ProtocolParseError};
33
/// Represents an accelerometer event from the protocol.
44
#[derive(PartialEq, Debug)]
55
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
6+
#[allow(missing_docs)] // the names are already obvious enough
67
pub struct AccelerometerEvent {
78
x: f32,
89
y: f32,
@@ -29,6 +30,7 @@ impl TryFrom<&[u8]> for AccelerometerEvent {
2930
}
3031
}
3132

33+
#[allow(missing_docs)] // the names are already obvious enough
3234
impl AccelerometerEvent {
3335
pub fn x(&self) -> f32 {
3436
self.x

src/button_event.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ use super::ProtocolParseError;
44
#[derive(PartialEq, Eq, Debug)]
55
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
66
pub enum ButtonParseError {
7+
/// The message contained an unknown button. For the known buttons see [`Button`].
78
UnknownButton(u8),
9+
/// The message contained an unknown button state. For the known button states see [`ButtonState`].
810
UnknownButtonState(u8),
911
}
1012

1113
/// Lists all possible buttons which can be sent in the event.
1214
#[derive(PartialEq, Eq, Debug)]
1315
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
16+
#[allow(missing_docs)] // the names are already obvious enough
1417
pub enum Button {
1518
Button1,
1619
Button2,
@@ -42,6 +45,7 @@ impl Button {
4245
/// The state of the button.
4346
#[derive(PartialEq, Eq, Debug)]
4447
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
48+
#[allow(missing_docs)] // the names are already obvious enough
4549
pub enum ButtonState {
4650
Released,
4751
Pressed,
@@ -61,6 +65,7 @@ impl ButtonState {
6165
/// Represents a button event from the protocol.
6266
#[derive(PartialEq, Eq, Debug)]
6367
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
68+
#[allow(missing_docs)] // the names are already obvious enough
6469
pub struct ButtonEvent {
6570
button: Button,
6671
state: ButtonState,
@@ -86,6 +91,7 @@ impl TryFrom<&[u8]> for ButtonEvent {
8691
}
8792
}
8893

94+
#[allow(missing_docs)] // the names are already obvious enough
8995
impl ButtonEvent {
9096
pub fn button(&self) -> &Button {
9197
&self.button

src/color_event.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use super::ProtocolParseError;
33
/// Represents a color event from the protocol.
44
#[derive(PartialEq, Eq, Debug)]
55
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
6+
#[allow(missing_docs)] // the names are already obvious enough
67
pub struct ColorEvent {
78
red: u8,
89
green: u8,
@@ -29,6 +30,7 @@ impl TryFrom<&[u8]> for ColorEvent {
2930
}
3031
}
3132

33+
#[allow(missing_docs)] // the names are already obvious enough
3234
impl ColorEvent {
3335
pub fn red(&self) -> u8 {
3436
self.red

src/gyro_event.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use super::{try_f32_from_le_bytes, ProtocolParseError};
33
/// Represents a gyro event from the protocol.
44
#[derive(PartialEq, Debug)]
55
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
6+
#[allow(missing_docs)] // the names are already obvious enough
67
pub struct GyroEvent {
78
x: f32,
89
y: f32,
@@ -29,6 +30,7 @@ impl TryFrom<&[u8]> for GyroEvent {
2930
}
3031
}
3132

33+
#[allow(missing_docs)] // the names are already obvious enough
3234
impl GyroEvent {
3335
pub fn x(&self) -> f32 {
3436
self.x

src/lib.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
//! Implements the [Controller Protocol](https://learn.adafruit.com/bluefruit-le-connect/controller) from Adafruit.
1+
//! Implements the [Controller Protocol](https://learn.adafruit.com/bluefruit-le-connect/controller) from Adafruit
2+
//! which is e.g. used by the [Adafruit Bluefruit LE UART Friend](https://learn.adafruit.com/introducing-the-adafruit-bluefruit-le-uart-friend).
23
3-
#![deny(unsafe_code)]
4+
#![forbid(unsafe_code)]
5+
// use deny instead of forbid due to bogus warnings, see also https://github.com/rust-lang/rust/issues/81670
46
#![deny(warnings)]
7+
#![deny(missing_docs)]
8+
#![forbid(missing_debug_implementations)]
9+
// use deny instead of forbid due to bogus warnings, see also https://github.com/rust-lang/rust/issues/81670
10+
#![deny(unused)]
511
#![no_std]
612

713
mod accelerometer_event;
@@ -25,6 +31,7 @@ pub use quaternion_event::QuaternionEvent;
2531
/// 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.
2632
#[derive(PartialEq, Debug)]
2733
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
34+
#[allow(missing_docs)] // the names are already obvious enough
2835
pub enum ControllerEvent {
2936
ButtonEvent(ButtonEvent),
3037
ColorEvent(ColorEvent),
@@ -39,16 +46,22 @@ pub enum ControllerEvent {
3946
#[derive(PartialEq, Eq, Debug)]
4047
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
4148
pub enum ProtocolParseError {
49+
/// The message contained an event which is not known to the current implementation. This can either mean that the message was malformed or that a newer protocol version has been used.
4250
UnknownEvent(Option<u8>),
51+
/// An error occurred while parsing a [`ButtonEvent`].
4352
ButtonParseError(ButtonParseError),
53+
/// The event in the message did not have the expected length.
4454
InvalidLength(usize, usize),
55+
/// The event in the message did not have the expected CRC.
4556
InvalidCrc(u8, u16),
57+
/// There was a problem parsing a float from a message.
4658
InvalidFloatSize(usize),
4759
}
4860

49-
/// Lists all (supported) data packages which can be sent by the controller. Internal state used during parsing. Use [`ControllerEvent`] to return the actual event.
61+
/// Lists all data packages which can be sent by the controller. Internal state used during parsing. Use [`ControllerEvent`] to return the actual event.
5062
#[derive(PartialEq, Eq, Debug)]
5163
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
64+
#[allow(missing_docs)] // the names are already obvious enough
5265
enum ControllerDataPackageType {
5366
ButtonCommand,
5467
Color,
@@ -143,7 +156,7 @@ fn parse_command(
143156
command: ControllerDataPackageType,
144157
command_input: &[u8],
145158
) -> Result<ControllerEvent, ProtocolParseError> {
146-
#[cfg(feature="defmt")]
159+
#[cfg(feature = "defmt")]
147160
defmt::debug!(
148161
"parsing the command of type {} from message {:a}",
149162
command,
@@ -193,7 +206,7 @@ fn parse_command(
193206

194207
/// Check the CRC of a command
195208
fn check_crc(data: &[u8], crc: &u8) -> Result<(), ProtocolParseError> {
196-
#[cfg(feature="defmt")]
209+
#[cfg(feature = "defmt")]
197210
defmt::trace!("calculating CRC for {:a}, expecting {}", data, crc);
198211

199212
let mut sum: u16 = 0;

src/location_event.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use super::{try_f32_from_le_bytes, ProtocolParseError};
33
/// Represents a location event from the protocol.
44
#[derive(PartialEq, Debug)]
55
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
6+
#[allow(missing_docs)] // the names are already obvious enough
67
pub struct LocationEvent {
78
latitude: f32,
89
longitude: f32,
@@ -29,6 +30,7 @@ impl TryFrom<&[u8]> for LocationEvent {
2930
}
3031
}
3132

33+
#[allow(missing_docs)] // the names are already obvious enough
3234
impl LocationEvent {
3335
pub fn latitude(&self) -> f32 {
3436
self.latitude

src/magnetometer_event.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use super::{try_f32_from_le_bytes, ProtocolParseError};
33
/// Represents a magnetometer event from the protocol.
44
#[derive(PartialEq, Debug)]
55
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
6+
#[allow(missing_docs)] // the names are already obvious enough
67
pub struct MagnetometerEvent {
78
x: f32,
89
y: f32,
@@ -29,6 +30,7 @@ impl TryFrom<&[u8]> for MagnetometerEvent {
2930
}
3031
}
3132

33+
#[allow(missing_docs)] // the names are already obvious enough
3234
impl MagnetometerEvent {
3335
pub fn x(&self) -> f32 {
3436
self.x

src/quaternion_event.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use super::{try_f32_from_le_bytes, ProtocolParseError};
22

3-
/// Represents a quaternion event from the protocol.
3+
/// Represents a [quaternion](https://en.wikipedia.org/wiki/Quaternion) event from the protocol.
44
#[derive(PartialEq, Debug)]
55
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
6+
#[allow(missing_docs)] // the names are already obvious enough
67
pub struct QuaternionEvent {
78
x: f32,
89
y: f32,
@@ -31,6 +32,7 @@ impl TryFrom<&[u8]> for QuaternionEvent {
3132
}
3233
}
3334

35+
#[allow(missing_docs)] // the names are already obvious enough
3436
impl QuaternionEvent {
3537
pub fn x(&self) -> f32 {
3638
self.x

0 commit comments

Comments
 (0)