mirror of
https://github.com/lune-org/lune.git
synced 2025-04-10 21:40:54 +01:00
Add example usage doc to label enum
This commit is contained in:
parent
b04c0c209d
commit
896121ab0d
1 changed files with 23 additions and 5 deletions
|
@ -2,6 +2,24 @@ use std::fmt;
|
||||||
|
|
||||||
use console::{style, Color};
|
use console::{style, Color};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Label enum used for consistent output formatting throughout Lune.
|
||||||
|
|
||||||
|
# Example usage
|
||||||
|
|
||||||
|
```rs
|
||||||
|
use lune_utils::fmt::Label;
|
||||||
|
|
||||||
|
println!("{} This is an info message", Label::Info);
|
||||||
|
// [INFO] This is an info message
|
||||||
|
|
||||||
|
println!("{} This is a warning message", Label::Warn);
|
||||||
|
// [WARN] This is a warning message
|
||||||
|
|
||||||
|
println!("{} This is an error message", Label::Error);
|
||||||
|
// [ERROR] This is an error message
|
||||||
|
```
|
||||||
|
*/
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum Label {
|
pub enum Label {
|
||||||
Info,
|
Info,
|
||||||
|
@ -11,14 +29,14 @@ pub enum Label {
|
||||||
|
|
||||||
impl Label {
|
impl Label {
|
||||||
/**
|
/**
|
||||||
Returns the name of the label in lowercase.
|
Returns the name of the label in all uppercase.
|
||||||
*/
|
*/
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
Self::Info => "info",
|
Self::Info => "INFO",
|
||||||
Self::Warn => "warn",
|
Self::Warn => "WARN",
|
||||||
Self::Error => "error",
|
Self::Error => "ERROR",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +59,7 @@ impl fmt::Display for Label {
|
||||||
f,
|
f,
|
||||||
"{}{}{}",
|
"{}{}{}",
|
||||||
style("[").dim(),
|
style("[").dim(),
|
||||||
style(self.name().to_ascii_uppercase()).fg(self.color()),
|
style(self.name()).fg(self.color()),
|
||||||
style("]").dim()
|
style("]").dim()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue