From 117077b1812eead796b12f9ed9ae64db57ee6060 Mon Sep 17 00:00:00 2001 From: Oren Hazi Date: Mon, 19 Feb 2024 11:17:57 -0800 Subject: [PATCH 1/2] Fix panic when trying to display a ParseError::InvalidByteCount --- src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 58dba71..f3700e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -297,7 +297,7 @@ impl fmt::Display for ParseError { f, "Invalid byte count; Matched `{}` bytes ({:?})", found, - &eui[..found] + eui ), } } @@ -745,6 +745,10 @@ mod tests { "Err(InvalidByteCount(7, [18, 52, 86, 171, 205, 239]))".to_owned(), format!("{:?}", MacAddress::parse_str("123456ABCDEF1")) ); + assert_eq!( + "Invalid byte count; Matched `7` bytes ([18, 52, 86, 171, 205, 239])".to_owned(), + format!("{}", ParseError::InvalidByteCount(7, [18, 52, 86, 171, 205, 239])) + ); assert_eq!( "Err(InvalidLength(19))", format!("{:?}", MacAddress::parse_str("12##45#67#89#AB#C#D")) From 9db7ee5f4f82b002cc6686b5d67e06fee447f615 Mon Sep 17 00:00:00 2001 From: Oren Hazi Date: Mon, 19 Feb 2024 11:37:25 -0800 Subject: [PATCH 2/2] Make fmt test more readable --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index f3700e6..0bf245d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -747,7 +747,7 @@ mod tests { ); assert_eq!( "Invalid byte count; Matched `7` bytes ([18, 52, 86, 171, 205, 239])".to_owned(), - format!("{}", ParseError::InvalidByteCount(7, [18, 52, 86, 171, 205, 239])) + format!("{}", MacAddress::parse_str("123456ABCDEF1").unwrap_err()) ); assert_eq!( "Err(InvalidLength(19))",