-
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
Review of key-value feature #584
Conversation
@@ -83,6 +83,11 @@ macro_rules! as_sval { | |||
/// - Using the `ToValue` trait. | |||
/// - Using the standard `From` trait. | |||
/// | |||
// REVIEW: maybe add a section about which conversion method to use and when? Or |
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_*
, then from_*
. The reason being if you Value::capture_display(&42)
you'll get a number, but if you use Value::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 for Display
and Debug
since serde
and sval
are naturally structured. We could also consider offering just a single capture
method that is what capture_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 like ToValue
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 use as_{debug,display,serde,sval}
. Then, once specialisation is stablised (and log's MSRV is updated), we could even add impl<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.
Does it make sense to change the macros to always call log::ToValue::to_value($value)?
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 to Display + 'static
means a lot of library types like Uuid
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 for Display
/Debug
/Serialize
/Value
. If we did that then we could remove the capture_*
methods altogether; they only exist to support downcasting to tell if we're logging numbers/booleans etc.
Then, once specialisation is stablised
🥲
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)?
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.
👍 makes sense
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.
We can keep using the as_display
/as_debug
macros, or shorten them to /?
, but perhaps that a different discussion.
Then, once specialisation is stablised
🥲
Indeed.
Thanks for all the time you've spent digging through this so far @Thomasdezeeuw! I think we're getting towards something that feels appropriate for the |
Just checking back in on this, is the main blocker we've got deciding whether to default to capturing using |
Yes, I think those are the two main things from this pr. |
I'm doing some work on this now; removing the It looks like we already default to using Are you happy with that plan @Thomasdezeeuw? |
I've opened #613 for this. I'll cc there once it's ready for review, but wanted to point it out here too. |
Yes, sounds good 👍 |
Discussion for #328.