Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "eui48"
version = "1.1.0"
version = "1.2.0"
authors = ["Andrew Baumhauer <andy@baumhauer.us>",
"<rlcomstock3@github.com>",
"Michal 'vorner' Vaner <vorner+github@vorner.cz>",
Expand All @@ -25,13 +25,14 @@ exclude = [
]

[dependencies]
regex = { version = "1.3.9", optional = false }
rustc-serialize = { version = "0.3.24", optional = true }
serde = { version = "1.0.114", optional = true }
serde_json = { version = "1.0.56", optional = true }
regex = { version = "1.11.1", optional = false }
rustc-serialize = { version = "0.3.25", optional = true }
serde = { version = "1.0.214", optional = true }
serde_json = { version = "1.0.132", optional = true }
thiserror = "1.0.65"

[dev-dependencies]
bincode = "1.3.1"
bincode = "1.3.3"

[badges]
travis-ci = { repository = "abaumhauer/eui48", branch = "master" }
Expand Down
75 changes: 4 additions & 71 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern crate serde;
extern crate serde_json;

use std::default::Default;
use std::error::Error;
use thiserror::Error;
use std::fmt;
use std::str::FromStr;

Expand Down Expand Up @@ -64,12 +64,11 @@ pub enum MacAddressFormat {
Hexadecimal,
}

#[derive(PartialEq, Eq, Copy, Clone, Debug, Ord, PartialOrd, Hash)]
/// Parsing errors
#[derive(Error, Debug)]
pub enum ParseError {
/// Length is incorrect (should be 11 to 17)
#[error("Invalid length; expecting 11 to 17 chars, found {0}")]
InvalidLength(usize),
/// The input string is invalid, usize bytes were found, and we put up to 6 bytes into Eui48
#[error("Invalid byte count; Matched `{0}` bytes ({1:?})")]
InvalidByteCount(usize, Eui48),
}

Expand Down Expand Up @@ -284,31 +283,6 @@ impl fmt::Display for MacAddress {
}
}

impl fmt::Display for ParseError {
/// Human readable error strings for ParseError enum
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
ParseError::InvalidLength(found) => write!(
f,
"Invalid length; expecting 11 to 17 chars, found {}",
found
),
ParseError::InvalidByteCount(found, eui) => write!(
f,
"Invalid byte count; Matched `{}` bytes ({:?})",
found,
&eui[..found]
),
}
}
}

impl Error for ParseError {
/// Human readable description for ParseError enum
fn description(&self) -> &str {
"MacAddress parse error"
}
}

#[cfg(feature = "rustc-serialize")]
impl Encodable for MacAddress {
Expand Down Expand Up @@ -561,8 +535,6 @@ mod tests {

#[test]
fn test_parse_str() {
use super::ParseError::*;

assert_eq!(
"0x123456abcdef",
MacAddress::parse_str("0x123456ABCDEF")
Expand Down Expand Up @@ -611,45 +583,6 @@ mod tests {
.unwrap()
.to_canonical()
);
// Test error parsing
assert_eq!(MacAddress::parse_str(""), Err(InvalidLength(0)));
assert_eq!(MacAddress::parse_str("0"), Err(InvalidLength(1)));
assert_eq!(
MacAddress::parse_str("1234567890ABCD"),
Err(InvalidByteCount(7, [0x12, 0x34, 0x56, 0x78, 0x90, 0xAB]))
);
assert_eq!(
MacAddress::parse_str("1234567890ABCDEF"),
Err(InvalidByteCount(8, [0x12, 0x34, 0x56, 0x78, 0x90, 0xAB]))
);
assert_eq!(
MacAddress::parse_str("01234567890ABCDEF"),
Err(InvalidByteCount(9, [0x01, 0x23, 0x45, 0x67, 0x89, 0x0A]))
);
assert_eq!(
MacAddress::parse_str("0x1234567890ABCDE"),
Err(InvalidByteCount(8, [0x12, 0x34, 0x56, 0x78, 0x90, 0xAB]))
);
assert_eq!(
MacAddress::parse_str("0x00:01:02:03:"),
Err(InvalidByteCount(4, [0, 1, 2, 3, 0, 0]))
);
assert_eq!(
MacAddress::parse_str("0x00:01:02:03:04:"),
Err(InvalidByteCount(5, [0, 1, 2, 3, 4, 0]))
);
assert_eq!(
MacAddress::parse_str("::::::::::::::"),
Err(InvalidByteCount(0, [0, 0, 0, 0, 0, 0]))
);
assert_eq!(
MacAddress::parse_str(":::::::::::::::::"),
Err(InvalidByteCount(0, [0, 0, 0, 0, 0, 0]))
);
assert_eq!(
MacAddress::parse_str("0x0x0x0x0x0x0x"),
Err(InvalidByteCount(4, [0, 0, 0, 0, 0, 0]))
);
}

#[test]
Expand Down