-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
trace: Add shorthand syntax for local fields #1103
Conversation
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
c2ba3b5
to
9729fba
Compare
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
because apparently this is a thing that matters
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
@carllerche, I'd like to go ahead and merge this, but I figured I'd ping you first in case you want to take a closer look. |
i'm not in love w/ |
Could something like: |
@carllerche I agree that using the assignment operator to indicate unassigned fields is definitely a bit strange, and I'm open to a different syntax. I have a couple of quibbles about
So, I'm open to this syntax if a majority of folks agree it's better. I'm still not really in love with any of the options we've got here, using the field name without an assignment was probably the best fit for this meaning. But the case of using local variables is even more common, and allowing shorthand for that definitely improves ergonomics. It's just a shame that there isn't really an obvious, natural syntax for unassigned fields. I'm still open to suggestions. |
? |
@jonhoo, @davidbarsky, @LucioFranco, you've all weighed in on this in the past --- any thoughts on Carl's suggestions? What seems the most intuitive to you? |
I still like |
Unless anyone else using I'm also open to Carl's suggestion of |
I don't want to move forward with |
(unless others think I am wrong and the syntax makes sense). |
why not |
I prefer the |
|
|
There are a couple reasons I don't think this is a great option:
Another potential option I thought was worth bringing up again is @jonhoo's suggestion of |
In order to move forwards with the local field shorthand, I'm considering punting on the replacement syntax for uninitialized fields for now, and adding that in a future PR once we can agree on an appropriate syntax. This means that the @jonhoo, @davidbarsky, @LucioFranco, do any of you have any objections to that? The alternative is trying to reach a consensus on a replacement syntax. |
Seems fine to me |
I personally do not need this right away, so im always +1 on punting (I like procrastinating anyways :D ) |
@hawkw would adding support later require a change to -core? |
@carllerche no, |
@hawkw +1 on punting. |
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Okay, I've removed the |
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Was changing the |
Nope, that was definitely not intentional! A fix would be very appreciated. |
I put up a fix in PR #1170 |
## Motivation A common pattern in `tokio-trace` is to use the value of a local variable as a field on a span or event. Currently, this requires code like: ```rust info!(foo = foo); ``` which is not particularly ergonomic given how commonly this occurs. Struct initializers support a shorthand syntax for fields where the name of the field is the same as a local variable, and `tokio-trace` should as well. ## Solution This branch adds support for syntax like ```rust let foo = ...; info!(foo); ``` and ```rust let foo = Foo { bar: ..., ... }; info!(foo.bar) ``` to the `tokio-trace` span and event macros. This syntax also works with the `Debug` and `Display` field shorthand. The span macros previously used a field name with no value to indicate an uninitialized field. A new issue, #1138, has been opened for finding a replacement syntax for uninitialized fields. Until then, the `tokio-trace` macros will no longer provide a way to create fields without values, although the `-core` API will continue to support this. Closes #1062 Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Motivation
A common pattern in
tokio-trace
is to use the value of a localvariable as a field on a span or event. Currently, this requires code
like:
which is not particularly ergonomic given how commonly this occurs.
Struct initializers support a shorthand syntax for fields where the name
of the field is the same as a local variable, and
tokio-trace
shouldas well.
Solution
This branch adds support for syntax like
and
to the
tokio-trace
span and event macros. This syntax also works withthe
Debug
andDisplay
field shorthand.The span macros previously used a field name with no value to indicate
an uninitialized field. A new issue, #1138, has been opened for finding a
replacement syntax for uninitialized fields. Until then, the
tokio-trace
macros will no longer provide a way to create fields without values,
although the
-core
API will continue to support this.Closes #1062
Signed-off-by: Eliza Weisman eliza@buoyant.io