Skip to content

Commit

Permalink
fix clippy::result_unit_err
Browse files Browse the repository at this point in the history
Signed-off-by: Serban Iorga <[email protected]>
  • Loading branch information
Serban Iorga committed May 21, 2021
1 parent eb27c8a commit 31de1b4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/utils/src/net/mac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl MacAddr {
}

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

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

assert!(MacAddr::from_bytes(&src1[..]).is_err());
assert!(MacAddr::from_bytes(&src1[..]).is_none());

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

assert!(MacAddr::from_bytes(&src3[..]).is_err());
assert!(MacAddr::from_bytes(&src3[..]).is_none());
}

#[test]
Expand Down

0 comments on commit 31de1b4

Please sign in to comment.