From e5d0773040637a1d7941b9a435d8a9fa1274f3f4 Mon Sep 17 00:00:00 2001 From: BonnetPonta Date: Wed, 10 Jun 2026 19:07:35 +0900 Subject: [PATCH] refactor: simplify match patterns --- src/filters/abstract_network.rs | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/filters/abstract_network.rs b/src/filters/abstract_network.rs index b97c9b33..2df8b8d6 100644 --- a/src/filters/abstract_network.rs +++ b/src/filters/abstract_network.rs @@ -169,7 +169,7 @@ fn parse_filter_options(raw_options: &str) -> Result, N ); result.push(match (option, negation) { - ("domain", _) | ("from", _) => { + ("domain" | "from", _) => { let domains: Vec<(bool, String)> = value .split('|') .map(|domain| { @@ -192,8 +192,8 @@ fn parse_filter_options(raw_options: &str) -> Result, N ("important", false) => NetworkFilterOption::Important, ("match-case", true) => return Err(NetworkFilterError::NegatedOptionMatchCase), ("match-case", false) => NetworkFilterOption::MatchCase, - ("third-party", negated) | ("3p", negated) => NetworkFilterOption::ThirdParty(!negated), - ("first-party", negated) | ("1p", negated) => NetworkFilterOption::FirstParty(!negated), + ("third-party" | "3p", negated) => NetworkFilterOption::ThirdParty(!negated), + ("first-party" | "1p", negated) => NetworkFilterOption::FirstParty(!negated), ("tag", true) => return Err(NetworkFilterError::NegatedTag), ("tag", false) => NetworkFilterOption::Tag(String::from(value)), ("redirect", true) => return Err(NetworkFilterError::NegatedRedirection), @@ -228,27 +228,19 @@ fn parse_filter_options(raw_options: &str) -> Result, N } NetworkFilterOption::Removeparam(String::from(value)) } - ("generichide", true) | ("ghide", true) => { - return Err(NetworkFilterError::NegatedGenericHide) - } - ("generichide", false) | ("ghide", false) => NetworkFilterOption::Generichide, - ("document", true) | ("doc", true) => return Err(NetworkFilterError::NegatedDocument), - ("document", false) | ("doc", false) => NetworkFilterOption::Document, + ("generichide" | "ghide", true) => return Err(NetworkFilterError::NegatedGenericHide), + ("generichide" | "ghide", false) => NetworkFilterOption::Generichide, + ("document" | "doc", true) => return Err(NetworkFilterError::NegatedDocument), + ("document" | "doc", false) => NetworkFilterOption::Document, ("image", negated) => NetworkFilterOption::Image(!negated), ("media", negated) => NetworkFilterOption::Media(!negated), - ("object", negated) | ("object-subrequest", negated) => { - NetworkFilterOption::Object(!negated) - } + ("object" | "object-subrequest", negated) => NetworkFilterOption::Object(!negated), ("other", negated) => NetworkFilterOption::Other(!negated), - ("ping", negated) | ("beacon", negated) => NetworkFilterOption::Ping(!negated), + ("ping" | "beacon", negated) => NetworkFilterOption::Ping(!negated), ("script", negated) => NetworkFilterOption::Script(!negated), - ("stylesheet", negated) | ("css", negated) => NetworkFilterOption::Stylesheet(!negated), - ("subdocument", negated) | ("frame", negated) => { - NetworkFilterOption::Subdocument(!negated) - } - ("xmlhttprequest", negated) | ("xhr", negated) => { - NetworkFilterOption::XmlHttpRequest(!negated) - } + ("stylesheet" | "css", negated) => NetworkFilterOption::Stylesheet(!negated), + ("subdocument" | "frame", negated) => NetworkFilterOption::Subdocument(!negated), + ("xmlhttprequest" | "xhr", negated) => NetworkFilterOption::XmlHttpRequest(!negated), ("websocket", negated) => NetworkFilterOption::Websocket(!negated), ("font", negated) => NetworkFilterOption::Font(!negated), ("all", true) => return Err(NetworkFilterError::NegatedAll),