Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: add as_str() for Level #1416

Merged
merged 1 commit into from
May 27, 2021
Merged

core: add as_str() for Level #1416

merged 1 commit into from
May 27, 2021

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 hawkw and a team 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