From 0bb4e3f9835559b48b97314d506fe21a65bd9ffb Mon Sep 17 00:00:00 2001 From: Zhang Jingqiang Date: Fri, 11 Oct 2024 15:49:27 +0800 Subject: [PATCH] remove useless attr and update error msg --- lib/g3-dpi/src/config/mod.rs | 2 -- lib/g3-types/src/acl/mod.rs | 2 -- lib/g3-yaml/src/value/acl/mod.rs | 9 ++++++--- lib/g3-yaml/src/value/dpi/policy/mod.rs | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/g3-dpi/src/config/mod.rs b/lib/g3-dpi/src/config/mod.rs index 3c12a3b2..dd2c2285 100644 --- a/lib/g3-dpi/src/config/mod.rs +++ b/lib/g3-dpi/src/config/mod.rs @@ -131,7 +131,6 @@ pub enum ProtocolInspectAction { } impl ProtocolInspectAction { - #[inline] fn as_str(&self) -> &'static str { match self { Self::Intercept => "intercept", @@ -156,7 +155,6 @@ impl fmt::Display for ProtocolInspectAction { impl FromStr for ProtocolInspectAction { type Err = (); - #[inline] fn from_str(s: &str) -> Result { match s.to_lowercase().as_str() { "intercept" => Ok(ProtocolInspectAction::Intercept), diff --git a/lib/g3-types/src/acl/mod.rs b/lib/g3-types/src/acl/mod.rs index 28ddefbd..686cb76f 100644 --- a/lib/g3-types/src/acl/mod.rs +++ b/lib/g3-types/src/acl/mod.rs @@ -68,7 +68,6 @@ impl AclAction { } impl AclAction { - #[inline] fn as_str(&self) -> &'static str { match self { AclAction::Permit => "Permit", @@ -90,7 +89,6 @@ impl fmt::Display for AclAction { impl FromStr for AclAction { type Err = (); - #[inline] fn from_str(s: &str) -> Result { match s.to_ascii_lowercase().as_str() { "permit" | "allow" | "accept" => Ok(AclAction::Permit), diff --git a/lib/g3-yaml/src/value/acl/mod.rs b/lib/g3-yaml/src/value/acl/mod.rs index 7f59c815..38c68556 100644 --- a/lib/g3-yaml/src/value/acl/mod.rs +++ b/lib/g3-yaml/src/value/acl/mod.rs @@ -41,10 +41,13 @@ pub use user_agent::as_user_agent_rule; fn as_action(value: &Yaml) -> anyhow::Result { if let Yaml::String(s) = value { - let action = AclAction::from_str(s).map_err(|_| anyhow!("invalid Action string value"))?; + let action = + AclAction::from_str(s).map_err(|_| anyhow!("invalid AclAction string value"))?; Ok(action) } else { - Err(anyhow!("the yaml value type for Action should be string")) + Err(anyhow!( + "the yaml value type for AclAction should be string" + )) } } @@ -64,7 +67,7 @@ trait AclRuleYamlParser { } _ => { let action = AclAction::from_str(k) - .map_err(|_| anyhow!("the key {k} is not a valid Action"))?; + .map_err(|_| anyhow!("the key {k} is not a valid AclAction"))?; if let Yaml::Array(seq) = v { for (i, v) in seq.iter().enumerate() { self.add_rule_for_action(action, v) diff --git a/lib/g3-yaml/src/value/dpi/policy/mod.rs b/lib/g3-yaml/src/value/dpi/policy/mod.rs index 2f0e00ed..bbdb0c5e 100644 --- a/lib/g3-yaml/src/value/dpi/policy/mod.rs +++ b/lib/g3-yaml/src/value/dpi/policy/mod.rs @@ -36,7 +36,7 @@ trait InspectRuleYamlParser { if let Yaml::Hash(map) = value { crate::foreach_kv(map, |k, v| { let action = ProtocolInspectAction::from_str(k) - .map_err(|_| anyhow!("the key {k} is not a valid Action"))?; + .map_err(|_| anyhow!("the key {k} is not a valid inspect action"))?; if let Yaml::Array(seq) = v { for (i, v) in seq.iter().enumerate() { self.add_rule_for_action(action, v)