Skip to content

Commit

Permalink
Simplify STATIC_MAX_LEVEL intialization
Browse files Browse the repository at this point in the history
Replace get_max_level_inner() with cfg!() and a const-compatible match,
now that the MSRV has been bumped to 1.60.0.
  • Loading branch information
ptosi committed Oct 20, 2023
1 parent cc7efd8 commit 296fa1a
Showing 1 changed file with 14 additions and 53 deletions.
67 changes: 14 additions & 53 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,59 +1482,20 @@ pub mod __private_api;
/// [`logger`]: fn.logger.html
pub const STATIC_MAX_LEVEL: LevelFilter = MAX_LEVEL_INNER;

const MAX_LEVEL_INNER: LevelFilter = get_max_level_inner();

const fn get_max_level_inner() -> LevelFilter {
#[allow(unreachable_code)]
{
#[cfg(all(not(debug_assertions), feature = "release_max_level_off"))]
{
return LevelFilter::Off;
}
#[cfg(all(not(debug_assertions), feature = "release_max_level_error"))]
{
return LevelFilter::Error;
}
#[cfg(all(not(debug_assertions), feature = "release_max_level_warn"))]
{
return LevelFilter::Warn;
}
#[cfg(all(not(debug_assertions), feature = "release_max_level_info"))]
{
return LevelFilter::Info;
}
#[cfg(all(not(debug_assertions), feature = "release_max_level_debug"))]
{
return LevelFilter::Debug;
}
#[cfg(all(not(debug_assertions), feature = "release_max_level_trace"))]
{
return LevelFilter::Trace;
}
#[cfg(feature = "max_level_off")]
{
return LevelFilter::Off;
}
#[cfg(feature = "max_level_error")]
{
return LevelFilter::Error;
}
#[cfg(feature = "max_level_warn")]
{
return LevelFilter::Warn;
}
#[cfg(feature = "max_level_info")]
{
return LevelFilter::Info;
}
#[cfg(feature = "max_level_debug")]
{
return LevelFilter::Debug;
}

LevelFilter::Trace
}
}
const MAX_LEVEL_INNER: LevelFilter = match cfg!(debug_assertions) {
false if cfg!(feature = "release_max_level_off") => LevelFilter::Off,
false if cfg!(feature = "release_max_level_error") => LevelFilter::Error,
false if cfg!(feature = "release_max_level_warn") => LevelFilter::Warn,
false if cfg!(feature = "release_max_level_info") => LevelFilter::Info,
false if cfg!(feature = "release_max_level_debug") => LevelFilter::Debug,
false if cfg!(feature = "release_max_level_trace") => LevelFilter::Trace,
_ if cfg!(feature = "max_level_off") => LevelFilter::Off,
_ if cfg!(feature = "max_level_error") => LevelFilter::Error,
_ if cfg!(feature = "max_level_warn") => LevelFilter::Warn,
_ if cfg!(feature = "max_level_info") => LevelFilter::Info,
_ if cfg!(feature = "max_level_debug") => LevelFilter::Debug,
_ => LevelFilter::Trace,
};

#[cfg(test)]
mod tests {
Expand Down

0 comments on commit 296fa1a

Please sign in to comment.