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

Implement conversions between Option<Level> and LevelFilter #644

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,21 @@ impl FromStr for LevelFilter {
}
}

impl From<LevelFilter> for Option<Level> {
fn from(level: LevelFilter) -> Option<Level> {
level.to_level()
}
}

impl From<Option<Level>> for LevelFilter {
fn from(level: Option<Level>) -> LevelFilter {
match level {
Some(level) => level.to_level_filter(),
None => LevelFilter::Off,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure this is always going to be obvious.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you leave out "not" or are you disagreeing with the comment above here and saying that this is actually fine and a reasonable choice to convert Option<Level>::None to LevelFilter::Off?

}
}
}

impl fmt::Display for LevelFilter {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.pad(self.as_str())
Expand Down