-
Notifications
You must be signed in to change notification settings - Fork 258
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
Expose logging levels #459
Conversation
Hey @WaDelma 👋 There probably isn't a great reason for this to be pub fn iter_all() -> impl Iterator<Item = Level> {
..
} That way in your code you could call something like: let names = Level::iter_all().map(|l| l.as_str()).collect(); The reason I think we should avoid making the array public is that it would be a breaking change to add any more levels (as unlikely as that is) because the type would change from |
Makes sense. I added such static methods for both |
@@ -560,6 +560,11 @@ impl Level { | |||
pub fn as_str(&self) -> &'static str { | |||
LOG_LEVEL_NAMES[*self as usize] | |||
} | |||
|
|||
/// Iterate through all supported logging levels | |||
pub fn iter() -> impl Iterator<Item = Self> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth documenting something about the order of these fields. Using from_usize
we’re effectively returning them in priority order.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this @WaDelma!
* Refactor: Avoid parsing `package.version()` twice in `ops::resolve` and `ops::install` * Optimize Resolution: Replace `Package<Meta>` with two `CompactStrings`: `name` and `version` * Use `CompactString` for `BinstallError::CratesIoApi::crate_name` * Use `CompactString` for `BinstallError::VersionParse::v` * Use `CompactString` for `BinstallError::VersionReq::req` * Use `CompactString` for `BinstallError::VersionUnavailable::crate_name` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
I am using
FromStr
implementation ofLevelFilter
to parse logging level given by user via command line flag. In case user gives invalid logging level I want to print list of allowed values. Currently I have to replicateLOG_LEVEL_NAMES
array in my code and remember to keep it in sync (It is probably unlikely it changes that much though).One question I have is that is there a reason it is
static
instead ofconst
?