From c40fe48a03b9246ce7e30af695baa374b353edf4 Mon Sep 17 00:00:00 2001 From: Leonardo Razovic Date: Thu, 9 Sep 2021 10:52:16 +0200 Subject: [PATCH 1/4] Add more `const fn` --- src/addr.rs | 6 +++--- src/addr6.rs | 2 +- src/addr8.rs | 2 +- src/parser/mod.rs | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/addr.rs b/src/addr.rs index d761bdd..0f25e68 100644 --- a/src/addr.rs +++ b/src/addr.rs @@ -21,7 +21,7 @@ impl MacAddr { /// assert_eq!(addr.is_v6(), true); /// assert_eq!(addr.is_v8(), false); /// ``` - pub fn is_v6(&self) -> bool { + pub const fn is_v6(&self) -> bool { match self { MacAddr::V6(_) => true, MacAddr::V8(_) => false, @@ -39,7 +39,7 @@ impl MacAddr { /// assert_eq!(addr.is_v6(), false); /// assert_eq!(addr.is_v8(), true); /// ``` - pub fn is_v8(&self) -> bool { + pub const fn is_v8(&self) -> bool { match self { MacAddr::V6(_) => false, MacAddr::V8(_) => true, @@ -58,7 +58,7 @@ impl MacAddr { /// /// assert_eq!(addr.as_bytes(), &[0xAC, 0xDE, 0x48, 0x23, 0x45, 0x67]); /// ``` - pub fn as_bytes(&self) -> &[u8] { + pub const fn as_bytes(&self) -> &[u8] { match self { MacAddr::V6(addr) => addr.as_bytes(), MacAddr::V8(addr) => addr.as_bytes(), diff --git a/src/addr6.rs b/src/addr6.rs index 289b9d7..cd7e474 100644 --- a/src/addr6.rs +++ b/src/addr6.rs @@ -148,7 +148,7 @@ impl MacAddr6 { /// /// assert_eq!(addr.as_bytes(), &[0xAC, 0xDE, 0x48, 0x23, 0x45, 0x67]); /// ``` - pub fn as_bytes(&self) -> &[u8] { + pub const fn as_bytes(&self) -> &[u8] { &self.0 } diff --git a/src/addr8.rs b/src/addr8.rs index 9c33d76..c79099a 100644 --- a/src/addr8.rs +++ b/src/addr8.rs @@ -148,7 +148,7 @@ impl MacAddr8 { /// /// assert_eq!(addr.as_bytes(), &[0xAC, 0xDE, 0x48, 0x23, 0x45, 0x67, 0x89, 0xAB]); /// ``` - pub fn as_bytes(&self) -> &[u8] { + pub const fn as_bytes(&self) -> &[u8] { &self.0 } diff --git a/src/parser/mod.rs b/src/parser/mod.rs index d7e81dc..5e61077 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -62,7 +62,7 @@ pub struct Parser<'a> { } impl<'a> Parser<'a> { - pub fn new(s: &'a str) -> Parser<'a> { + pub const fn new(s: &'a str) -> Parser<'a> { Parser { source: s.as_bytes(), pos: 0, @@ -70,7 +70,7 @@ impl<'a> Parser<'a> { } } - fn is_eof(&self) -> bool { + const fn is_eof(&self) -> bool { self.pos == self.source.len() } From da64478e5b414101f7497631ffadfe390fda83d8 Mon Sep 17 00:00:00 2001 From: Leonardo Razovic Date: Thu, 9 Sep 2021 10:52:41 +0200 Subject: [PATCH 2/4] Update `assert_matches` from 1.3 to 1.5 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3bb4603..c080062 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ serde_std = ["std", "serde/std"] serde = { version = "^1.0", default-features = false, features = ["derive"], optional = true } [dev-dependencies] -assert_matches = "1.3.0" +assert_matches = "1.5.0" [package.metadata.docs.rs] features = ["serde", "serde_std"] From bdc4d5c40e8a0b6d208265cbab946f71b8ba13d0 Mon Sep 17 00:00:00 2001 From: Leonardo Razovic Date: Thu, 9 Sep 2021 10:53:07 +0200 Subject: [PATCH 3/4] Replace deprecated `merge_imports` with `imports_granularity` --- rustfmt.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rustfmt.toml b/rustfmt.toml index 599ac80..fa68aee 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -4,6 +4,6 @@ version = "Two" wrap_comments = true comment_width = 120 max_width = 120 -merge_imports = false +imports_granularity="Preserve" newline_style = "Unix" struct_lit_single_line = false From 4ff1facef2762dd5a79dbd671bdcb52517218652 Mon Sep 17 00:00:00 2001 From: Leonardo Razovic Date: Thu, 9 Sep 2021 11:08:31 +0200 Subject: [PATCH 4/4] Add ticks to struct names in documentation --- src/parser/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 5e61077..c06dfa8 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -9,7 +9,7 @@ use crate::{MacAddr, MacAddr6, MacAddr8}; /// An error which can be returned when parsing MAC address. /// /// This error is used as the error type for the `FromStr` implementation -/// for [MacAddr6] and [MacAddr8]. +/// for [`MacAddr6`] and [`MacAddr8`]. /// /// [MacAddr6]: ./struct.MacAddr6.html /// [MacAddr8]: ./struct.MacAddr8.html