Skip to content

Commit

Permalink
core: add conversion from Option<Level> to LevelFilter (#966)
Browse files Browse the repository at this point in the history
Resolves a previously unreported issue where `Option<Level>` is not
a valid `LevelFilter`.
  • Loading branch information
davidbarsky authored Sep 5, 2020
1 parent fbaa2fd commit 11f577a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions tracing-core/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,13 @@ impl From<Level> for LevelFilter {
}
}

impl From<Option<Level>> for LevelFilter {
#[inline]
fn from(level: Option<Level>) -> Self {
Self(level)
}
}

impl Into<Option<Level>> for LevelFilter {
#[inline]
fn into(self) -> Option<Level> {
Expand Down Expand Up @@ -819,8 +826,15 @@ mod tests {
];
for (filter, level) in mapping.iter() {
assert_eq!(filter.clone().into_level(), *level);
if let Some(level) = level {
assert_eq!(LevelFilter::from_level(level.clone()), *filter);
match level {
Some(level) => {
let actual: LevelFilter = level.clone().into();
assert_eq!(actual, *filter);
}
None => {
let actual: LevelFilter = None.into();
assert_eq!(actual, *filter);
}
}
}
}
Expand Down

0 comments on commit 11f577a

Please sign in to comment.