Skip to content

Commit 18acdf3

Browse files
committed
can: Make frame constructors return Result
As noted by @marcelbuesing @reneherrero invalid identfiers can be passed which
1 parent a2463fa commit 18acdf3

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/can.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
//! Controller Area Network
22
33
/// A CAN2.0 Frame
4-
pub trait Frame {
5-
/// Creates a new frame with a standard identifier.
6-
fn new_standard(id: u32, data: &[u8]) -> Self;
7-
8-
/// Creates a new frame with an extended identifier.
9-
fn new_extended(id: u32, data: &[u8]) -> Self;
4+
pub trait Frame: Sized {
5+
/// Creates a new frame with a standard identifier (0..=0x7FF).
6+
/// Returns an error when the the identifier is not valid.
7+
fn new_standard(id: u16, data: &[u8]) -> Result<Self, ()>;
8+
9+
/// Creates a new frame with an extended identifier (0..=0x1FFF_FFFF).
10+
/// Returns an error when the the identifier is not valid.
11+
fn new_extended(id: u32, data: &[u8]) -> Result<Self, ()>;
1012

1113
/// Marks this frame as a remote frame (by setting the RTR bit).
1214
fn with_rtr(&mut self, dlc: usize) -> &mut Self;

0 commit comments

Comments
 (0)