Skip to content

Commit

Permalink
Use existing code instead of rewriting it
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 committed Apr 10, 2020
1 parent ba344ee commit 2daa009
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1171,18 +1171,11 @@ pub fn set_max_level(level: LevelFilter) {
/// [`set_max_level`]: fn.set_max_level.html
#[inline(always)]
pub fn max_level() -> LevelFilter {
match MAX_LOG_LEVEL_FILTER.load(Ordering::Relaxed) {
0 => LevelFilter::Off,
1 => LevelFilter::Error,
2 => LevelFilter::Warn,
3 => LevelFilter::Info,
4 => LevelFilter::Debug,
5 => LevelFilter::Trace,
// Since only this module has access to `MAX_LOG_LEVEL_FILTER`,
// and the only time `MAX_LOG_LEVEL_FILTER` is stored to is in `set_max_level`,
// the value will always be a valid enum member.
_ => unreachable!("only LevelFilter variants are possible"),
}
let level = MAX_LOG_LEVEL_FILTER.load(Ordering::Relaxed);
// Since only this module has access to `MAX_LOG_LEVEL_FILTER`,
// and the only time `MAX_LOG_LEVEL_FILTER` is stored to is in `set_max_level`,
// the value will always be a valid enum member.
LevelFilter::from_usize(level).unwrap()
}

/// Sets the global logger to a `Box<Log>`.
Expand Down

0 comments on commit 2daa009

Please sign in to comment.