From 8b6f4b23c120199eba730b87cf6452b89a425f64 Mon Sep 17 00:00:00 2001 From: Folyd Date: Wed, 26 May 2021 11:47:35 +0800 Subject: [PATCH 1/2] core: add `as_str()` for `Level` --- tracing-core/src/metadata.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tracing-core/src/metadata.rs b/tracing-core/src/metadata.rs index 0c621a97c4..dcee328365 100644 --- a/tracing-core/src/metadata.rs +++ b/tracing-core/src/metadata.rs @@ -283,6 +283,19 @@ impl Level { /// /// Designates very low priority, often extremely verbose, information. pub const TRACE: Level = Level(LevelInner::Trace); + + /// Get the string representation of the `Level`. + /// + /// This returns the same string as the `fmt::Display` implementation. + pub fn as_str(&self) -> &str { + match *self { + Level::TRACE => "TRACE", + Level::DEBUG => "DEBUG", + Level::INFO => "INFO", + Level::WARN => "WARN", + Level::ERROR => "ERROR", + } + } } impl fmt::Display for Level { From 98e71cc3547ac84b2d30f2b8845cf7b6261e0c7e Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Wed, 26 May 2021 09:29:55 -0700 Subject: [PATCH 2/2] Apply suggestions from code review --- tracing-core/src/metadata.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tracing-core/src/metadata.rs b/tracing-core/src/metadata.rs index dcee328365..5de3b1a2e4 100644 --- a/tracing-core/src/metadata.rs +++ b/tracing-core/src/metadata.rs @@ -284,10 +284,10 @@ impl Level { /// Designates very low priority, often extremely verbose, information. pub const TRACE: Level = Level(LevelInner::Trace); - /// Get the string representation of the `Level`. + /// Returns the string representation of the `Level`. /// /// This returns the same string as the `fmt::Display` implementation. - pub fn as_str(&self) -> &str { + pub fn as_str(&self) -> &'static str { match *self { Level::TRACE => "TRACE", Level::DEBUG => "DEBUG",