Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use unwrap_or_default() when getting default color and verbosity #2397

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ impl Color {
}

pub(crate) fn auto() -> Self {
Self {
use_color: UseColor::Auto,
..Self::default()
}
Self::default()
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn run(args: impl Iterator<Item = impl Into<OsString> + Clone>) -> Result<()
let (color, verbosity) = config
.as_ref()
.map(|config| (config.color, config.verbosity))
.unwrap_or((Color::auto(), Verbosity::default()));
.unwrap_or_default();

let loader = Loader::new();

Expand Down
30 changes: 14 additions & 16 deletions src/verbosity.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use Verbosity::*;

#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
pub(crate) enum Verbosity {
Quiet,
Taciturn,
Expand All @@ -11,35 +9,35 @@ pub(crate) enum Verbosity {
impl Verbosity {
pub(crate) fn from_flag_occurrences(flag_occurrences: u8) -> Self {
match flag_occurrences {
0 => Taciturn,
1 => Loquacious,
_ => Grandiloquent,
0 => Self::Taciturn,
1 => Self::Loquacious,
_ => Self::Grandiloquent,
}
}

pub(crate) fn quiet(self) -> bool {
matches!(self, Quiet)
self == Self::Quiet
}

pub(crate) fn loud(self) -> bool {
!self.quiet()
}

pub(crate) fn loquacious(self) -> bool {
match self {
Quiet | Taciturn => false,
Loquacious | Grandiloquent => true,
}
self >= Self::Loquacious
}

pub(crate) fn grandiloquent(self) -> bool {
match self {
Quiet | Taciturn | Loquacious => false,
Grandiloquent => true,
}
self >= Self::Grandiloquent
}

pub const fn default() -> Self {
Taciturn
Self::Taciturn
}
}

impl Default for Verbosity {
fn default() -> Self {
Self::default()
}
}