-
Notifications
You must be signed in to change notification settings - Fork 191
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
Add valuable
support for Uuid
s
#583
Comments
I've been expecting this for a while, so we've already got a bit of a plan in place 🙂 We've got As for representation, I think we'd probably be most useful implementing impl valuable::Valuable for Uuid {
// If you ask for a value you get our byte representation
fn as_value(&self) -> valuable::Value {
valuable::Valuable::as_value(&self.0)
}
// If you visit you get a hyphenated string
fn visit(&self, v: &mut dyn valuable::Visit) {
v.visit_value(valuable::Value::Displayable(self.hyphenated()))
}
} My gut feel on that though is "no that's a bad idea". |
I think it would be better to visit In terms of 16 bytes not representing the semantic meaning of a |
So for the I think part of the problem here may be that |
I agree that stringly-typed APIs are kinda sus. However, the official blog post specifically uses an example to inspect an HTTP header type with very specific fields. Furthermore, Another detail to consider is that providing the bytes for a |
Hmm, when would you expect an end-user of I think what’s missing from this discussion that’s going to keep us going in circles at the moment is more input on potential usecases for a |
Using tracing:An idea I had for Outside of tracingTo address your "going in circles" point: I think
if serializer.is_human_readable() {
serializer
.serialize_str(&self.to_hyphenated().encode_lower(&mut [0; 36]))
} else {
serializer.serialize_bytes(self.as_bytes())
} Making the // analogous to what's exposed by the `Valuable` impl
let value = self.to_hyphenated().encode_lower(&mut [0; 36]);
// analogous to what the downstream `valuable` user has to write
if serializer.is_human_readable() {
serializer
.serialize_str(value)
} else {
serializer.serialize_bytes(Uuid::parse_str(value).unwrap().as_bytes())
} This example seems dumb, because all these decisions are already made known to us (we can call Also, since this would be an unstable feature, wouldn't it still be okay to change the implementation down the line before it stabilizes if we decide we want to? If this is the case that I think we should try it this way and we can get feedback on it first. |
Yeh, I can see the value of the role I was thinking we could just copy the approach used for IP addresses in UUID, but I see we haven't got them yet in |
I've opened tokio-rs/valuable#87 to get some input from the |
Coming back around to this, it looks like we don't have a clear best path forward, so as much as I'd like to keep the default implementation of We can follow the same approach as |
interested in this functionality. Is there any outstanding work on this or is there interest for contributing a PR for this? |
Hi @kaiba42 👋 I'd be open to a PR that added this, but would like to see how a few alternative representations would work in the current |
Motivation
The Tokio team is releasing a new crate,
valuable
, which is intended to be used for passing in custom types as fields in logs. SinceUuid
s are commonly used in applications that also usetracing
like Kanidm, we should implement theValuable
trait behind a feature gate.Solution
Derive the
Valuable
trait.Alternatives
Uuid
s as strings.Uuid
and rely on usingas_bytes
in the trait implementation. This would be incredibly annoying though, because it would mean applications would have to use:Hopefully
tracing
will add a sigil to reduce verbosity withas_value()
similar to how?
and%
are used forDebug
andDisplay
formatting, but avoiding a wrapper type would be ideal.Is it blocking?
No
Anything else?
The
valuable
crate is still in the very early stages, and could possibly have breaking changes. However, I think the very minimal API that this crate would depend on (just deriving the trait) is unlikely to change.The text was updated successfully, but these errors were encountered: