From 2daa0092224a9fcfdc283f05c3142ac54ff26053 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 9 Apr 2020 23:22:37 -0400 Subject: [PATCH] Use existing code instead of rewriting it --- src/lib.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5c40c707c..7452bf388 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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`.