Skip to content

Commit

Permalink
fix: address comments
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
  • Loading branch information
Rustin170506 committed Feb 10, 2024
1 parent 921e35d commit e7a610e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
13 changes: 8 additions & 5 deletions tokio-console/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<KnownWarnings>),
/// Represents the case where only some specific warnings are allowed.
/// The allowed warnings are stored in a `BTreeSet` of `KnownWarnings`.
Explicit(BTreeSet<KnownWarnings>),
}

impl FromStr for AllowedWarnings {
Expand All @@ -206,7 +209,7 @@ impl FromStr for AllowedWarnings {
.map(|s| s.parse::<KnownWarnings>())
.collect::<Result<BTreeSet<_>, _>>()
.map_err(|err| format!("failed to parse warning: {}", err))?;
Ok(AllowedWarnings::Some(warnings))
Ok(AllowedWarnings::Explicit(warnings))
}
}
}
Expand All @@ -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)
}
}
}
Expand Down
14 changes: 6 additions & 8 deletions tokio-console/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<TaskDetails>(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::<Vec<_>>(),
},
Some(AllowedWarnings::All) => vec![],
Some(AllowedWarnings::Explicit(allow_warnings)) => args
.warnings
.iter()
.filter(|lint| !allow_warnings.contains(lint))
.collect::<Vec<_>>(),
None => args.warnings.iter().collect::<Vec<_>>(),
};

Expand Down

0 comments on commit e7a610e

Please sign in to comment.