Skip to content

Commit

Permalink
remove useless attr and update error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-jq-b committed Oct 11, 2024
1 parent 740b0a9 commit 0bb4e3f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 0 additions & 2 deletions lib/g3-dpi/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ pub enum ProtocolInspectAction {
}

impl ProtocolInspectAction {
#[inline]
fn as_str(&self) -> &'static str {
match self {
Self::Intercept => "intercept",
Expand All @@ -156,7 +155,6 @@ impl fmt::Display for ProtocolInspectAction {
impl FromStr for ProtocolInspectAction {
type Err = ();

#[inline]
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"intercept" => Ok(ProtocolInspectAction::Intercept),
Expand Down
2 changes: 0 additions & 2 deletions lib/g3-types/src/acl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ impl AclAction {
}

impl AclAction {
#[inline]
fn as_str(&self) -> &'static str {
match self {
AclAction::Permit => "Permit",
Expand All @@ -90,7 +89,6 @@ impl fmt::Display for AclAction {
impl FromStr for AclAction {
type Err = ();

#[inline]
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_ascii_lowercase().as_str() {
"permit" | "allow" | "accept" => Ok(AclAction::Permit),
Expand Down
9 changes: 6 additions & 3 deletions lib/g3-yaml/src/value/acl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ pub use user_agent::as_user_agent_rule;

fn as_action(value: &Yaml) -> anyhow::Result<AclAction> {
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"
))
}
}

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/g3-yaml/src/value/dpi/policy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0bb4e3f

Please sign in to comment.