Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Review of key-value feature #584
Review of key-value feature #584
Changes from all commits
0838b1c
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Good call 👍
The preference would be for
capture_*
, thenfrom_*
. The reason being if youValue::capture_display(&42)
you'll get a number, but if you useValue::from_display(&42)
you'll get a string. I'd be open to some different naming that made this more obvious. We may consider also only adding them forDisplay
andDebug
sinceserde
andsval
are naturally structured. We could also consider offering just a singlecapture
method that is whatcapture_display
currently is, and using that by default in the macros. The goal is that by default if you log a boolean or number you should get a boolean or number, and you shouldn't have to implement any non-standard-library traits likeToValue
to log something.I'm open to suggestions though. 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.
Does it make sense to change the macros to always call
log::ToValue::to_value($value)
? Then at least for the primitive types users don't have to worry about it. For non-primitive types users will have to useas_{debug,display,serde,sval}
. Then, once specialisation is stablised (and log's MSRV is updated), we could even addimpl<T: {fmt::Display,fmt::Debug,serde::Serialize,sval::Value}> ToValue for T { .. }
.As for the
capture_*
vs.from_*
, can we drop the'static
requirement of the type? If maybe we can merge them (or at least some methods).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.
The idea was to try discourage libraries from implementing
ToValue
themselves so it doesn't become yet another widespread piece of trivia that library authors need to keep on top of. Defaulting toDisplay + 'static
means a lot of library types likeUuid
can be captured, but the drawback of throwing lifetime errors at you if you try log a non-'static
value would be unpleasant.For what it's worth, I would be ok with using
ToValue
by default in addition to adding some easy syntax forDisplay
/Debug
/Serialize
/Value
. If we did that then we could remove thecapture_*
methods altogether; they only exist to support downcasting to tell if we're logging numbers/booleans etc.🥲
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.
👍 makes sense
We can keep using the
as_display
/as_debug
macros, or shorten them to /?
, but perhaps that a different discussion.Indeed.