net_util: Remove unit error from Result

error: this returns a `Result<_, ()>
  --> net_util/src/mac.rs:68:5
   |
68 |     pub fn from_bytes(src: &[u8]) -> Result<MacAddr, ()> {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `-D clippy::result-unit-err` implied by `-D warnings`
   = help: use a custom Error type instead
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#result_unit_err

Replace with std::io::Error like other locations in the same file.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2021-01-02 19:57:22 +00:00 committed by Sebastien Boeuf
parent d2de263774
commit a4134f6b25
2 changed files with 6 additions and 3 deletions

View File

@ -65,9 +65,12 @@ impl MacAddr {
// An error can only occur if the slice length is different from MAC_ADDR_LEN. // An error can only occur if the slice length is different from MAC_ADDR_LEN.
#[inline] #[inline]
pub fn from_bytes(src: &[u8]) -> Result<MacAddr, ()> { pub fn from_bytes(src: &[u8]) -> Result<MacAddr, io::Error> {
if src.len() != MAC_ADDR_LEN { if src.len() != MAC_ADDR_LEN {
return Err(()); return Err(io::Error::new(
io::ErrorKind::Other,
format!("invalid length of slice: {} vs {}", src.len(), MAC_ADDR_LEN),
));
} }
Ok(MacAddr::from_bytes_unchecked(src)) Ok(MacAddr::from_bytes_unchecked(src))
} }

View File

@ -31,7 +31,7 @@ pub enum Error {
NetUtil(NetUtilError), NetUtil(NetUtilError),
InvalidIfname, InvalidIfname,
/// Error parsing MAC data /// Error parsing MAC data
MacParsing(()), MacParsing(IoError),
} }
pub type Result<T> = ::std::result::Result<T, Error>; pub type Result<T> = ::std::result::Result<T, Error>;