Skip to content

Commit 31de1b4

Browse files
author
Serban Iorga
committed
fix clippy::result_unit_err
Signed-off-by: Serban Iorga <[email protected]>
1 parent eb27c8a commit 31de1b4

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/utils/src/net/mac.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl MacAddr {
9393
}
9494

9595
/// Create a `MacAddr` from a slice.
96-
/// An error will occur if the slice length is different from `MAC_ADDR_LEN`.
96+
/// This method will return None if the slice length is different from `MAC_ADDR_LEN`.
9797
/// # Arguments
9898
///
9999
/// * `src` - slice from which to copy MAC address content.
@@ -105,11 +105,11 @@ impl MacAddr {
105105
/// println!("{}", mac.to_string());
106106
/// ```
107107
#[inline]
108-
pub fn from_bytes(src: &[u8]) -> Result<MacAddr, ()> {
108+
pub fn from_bytes(src: &[u8]) -> Option<MacAddr> {
109109
if src.len() != MAC_ADDR_LEN {
110-
return Err(());
110+
return None;
111111
}
112-
Ok(MacAddr::from_bytes_unchecked(src))
112+
Some(MacAddr::from_bytes_unchecked(src))
113113
}
114114

115115
/// Return the underlying content of this `MacAddr` in bytes.
@@ -177,12 +177,12 @@ mod tests {
177177
let src2 = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06];
178178
let src3 = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07];
179179

180-
assert!(MacAddr::from_bytes(&src1[..]).is_err());
180+
assert!(MacAddr::from_bytes(&src1[..]).is_none());
181181

182182
let x = MacAddr::from_bytes(&src2[..]).unwrap();
183183
assert_eq!(x.to_string(), String::from("01:02:03:04:05:06"));
184184

185-
assert!(MacAddr::from_bytes(&src3[..]).is_err());
185+
assert!(MacAddr::from_bytes(&src3[..]).is_none());
186186
}
187187

188188
#[test]

0 commit comments

Comments
 (0)