-
Notifications
You must be signed in to change notification settings - Fork 24
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
Implement Serialization and Deserialization for Verbosity #114
base: master
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 11058763842Details
💛 - Coveralls |
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.
I will:
- remove rstest
- serialize to/from LevelFilter instead of Option(Level)
- add a specific test for TOML serialization
- Fix the github lints
- split the i8 change out to another commit (and will raise another PR for it if necessary)
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.
Moving to LevelFilter made it easy to derive serialize / deserialize using From<LevelFilter>
instead of a custom implementation.
} | ||
|
||
// round-trips | ||
let toml = "meaning_of_life = 42\nverbose = \"DEBUG\"\n"; |
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.
Not sure how I feel about deserializing to all-caps
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.
Yeah, this irks me a little too, but being consistent with the existing behavior won out over my ideal approach. If I was designing the log
crate, I think I'd have made that serialization lower case too.
Here, this can deserialize from either case, but serializes to upper case. It comes from the serialization of log::LevelFilter
. That means upper case is consistent with any other serialization that works with log level serialization (and is consistent with the usual display of the level in log outputs).
If you did want to avoid this, it would require going back to using a custom serialization implementation. This doesn't seem worth the extra code and tests to me. I prefer the simplicity even if that comes with a slightly ugly default which is consistent with other things doing the same thing.
I also suspect the serialization side of this will be used much less frequently than the deserialization side, and the serialization side will also often be more focused on programs re-reading the format rather than humans.
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.
On one hand, if people are serializing LevelFilter
, this keeps us consistent with that. On the other hand, this will produce results inconsistent with every other serialized value. This isn't just important here but for other cases like schemars. I think I want to let this sit for a time to mull over this.
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.
no problem :)
This commit adds serialization and deserialization support for the Verbosity type. The verbosity is serialized using the log::LevelFilter enum that represents the equivalent number of verbose and quiet flags. The serialized value is the uppercase variant of the enum variant. Deserialing is case-insensitive. Fixes: clap-rs#88
This commit adds serialization and deserialization support for the
Verbosity type. The verbosity is serialized as an optional log level
that represents the equivalent log level given the number of verbose and
quiet flags. When deserializing, the log level is converted into a
number of verbose and quiet flags, which keeps one of the flags at 0 and
the other at the difference between the log level and the default log
level.
The internal representation in calculations has been changed from i8 to
i16 to prevent overflows when performing calculations using u8 values.
Fixes: #88