From e7a610eee802133e63e4a22c8e5ed2b44205feaf Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Sat, 10 Feb 2024 09:39:47 +0800 Subject: [PATCH] fix: address comments Signed-off-by: hi-rustin --- tokio-console/src/config.rs | 13 ++++++++----- tokio-console/src/main.rs | 14 ++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/tokio-console/src/config.rs b/tokio-console/src/config.rs index 465dc41f8..bf4ee2608 100644 --- a/tokio-console/src/config.rs +++ b/tokio-console/src/config.rs @@ -187,11 +187,14 @@ impl KnownWarnings { ] } } - +/// An enum representing the types of warnings that are allowed. #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub(crate) enum AllowedWarnings { + /// Represents the case where all warnings are allowed. All, - Some(BTreeSet), + /// Represents the case where only some specific warnings are allowed. + /// The allowed warnings are stored in a `BTreeSet` of `KnownWarnings`. + Explicit(BTreeSet), } impl FromStr for AllowedWarnings { @@ -206,7 +209,7 @@ impl FromStr for AllowedWarnings { .map(|s| s.parse::()) .collect::, _>>() .map_err(|err| format!("failed to parse warning: {}", err))?; - Ok(AllowedWarnings::Some(warnings)) + Ok(AllowedWarnings::Explicit(warnings)) } } } @@ -217,10 +220,10 @@ impl AllowedWarnings { match (self, allowed) { (AllowedWarnings::All, _) => AllowedWarnings::All, (_, AllowedWarnings::All) => AllowedWarnings::All, - (AllowedWarnings::Some(a), AllowedWarnings::Some(b)) => { + (AllowedWarnings::Explicit(a), AllowedWarnings::Explicit(b)) => { let mut warnings = a.clone(); warnings.extend(b.clone()); - AllowedWarnings::Some(warnings) + AllowedWarnings::Explicit(warnings) } } } diff --git a/tokio-console/src/main.rs b/tokio-console/src/main.rs index 28f486f37..421c660a7 100644 --- a/tokio-console/src/main.rs +++ b/tokio-console/src/main.rs @@ -66,14 +66,12 @@ async fn main() -> color_eyre::Result<()> { // A channel to send the task details update stream (no need to keep outdated details in the memory) let (details_tx, mut details_rx) = mpsc::channel::(2); let warnings = match args.allow_warnings { - Some(allow_warnings) => match allow_warnings { - AllowedWarnings::All => vec![], - AllowedWarnings::Some(allow_warnings) => args - .warnings - .iter() - .filter(|lint| !allow_warnings.contains(lint)) - .collect::>(), - }, + Some(AllowedWarnings::All) => vec![], + Some(AllowedWarnings::Explicit(allow_warnings)) => args + .warnings + .iter() + .filter(|lint| !allow_warnings.contains(lint)) + .collect::>(), None => args.warnings.iter().collect::>(), };