Skip to content

Conversation

@Folyd
Copy link
Contributor

@Folyd Folyd commented May 27, 2021

Motivation

Get the string representation of the Level is quite a common usecase.
Without this method, I normally need to implement it by myself, which
is fairly noisy.

#[inline]
fn level_to_str(level: &tracing::Level) -> &'static str {
    match *level {
        tracing::Level::TRACE => "TRACE",
        tracing::Level::DEBUG => "DEBUG",
        tracing::Level::INFO => "INFO",
        tracing::Level::WARN => "WARN",
        tracing::Level::ERROR => "ERROR"
    }
}

Solution

Add an as_str() method for Level. Similar to [log::Level::as_str()][1].

[1] https://docs.rs/log/0.4.14/log/enum.Level.html#method.as_str

## Motivation

Get the string representation of the `Level` is quite a common usecase.
Without this method, I normally need to implement it by myself, which
is fairly noisy.

```rust
#[inline]
fn level_to_str(level: &tracing::Level) -> &'static str {
    match *level {
        tracing::Level::TRACE => "TRACE",
        tracing::Level::DEBUG => "DEBUG",
        tracing::Level::INFO => "INFO",
        tracing::Level::WARN => "WARN",
        tracing::Level::ERROR => "ERROR"
    }
}
```

## Solution

Add an `as_str()` method for `Level`. Similar to [log::Level::as_str()][1].

[1] https://docs.rs/log/0.4.14/log/enum.Level.html#method.as_str
@Folyd Folyd requested review from a team and hawkw as code owners May 27, 2021 02:57
@Folyd Folyd changed the title core: add as_str() for Level (#1413) core: add as_str() for Level May 27, 2021
@hawkw hawkw merged commit 9702bf5 into tokio-rs:v0.1.x May 27, 2021
@Folyd Folyd deleted the v0.1.x branch May 28, 2021 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants