Allow access of inner Uuid for Hyphenated, Simple, Urn #482
Labels
No labels
breaking
bug
dependencies
good first issue
help wanted
unstable
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-uuid-rs/uuid#482
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Is your feature request related to a problem? Please describe.
This PR was recently merged to sqlx, which allows for Uuid support for the mysql driver. Not only can this encode/decode to the basic Uuid type, but we'd also included Hyphenated in there too: https://github.com/launchbadge/sqlx/pull/536
This is especially helpful, because databases have a number of ways the UUID may be serialized back, e.g. the query may select hex-encoded hyphenated strings -- an increasingly common scenario, as these UUIDs may be pulled out of string fields, or stored json. We can encode + decode to a Hyphenated (or Simple, or Urn) easily enough, but it will force us to decode from a Hyphenated string if we ever want it as raw Bytes, even though those Bytes are already part of the struct.
Describe the solution you'd like
Any way to access the inner is fine. Not sure of the name -- a
From<Hyphenated> for Uuidwould be okay, as would.to_uuid(),.to_inner(), etc. I'd like it to keep to the style of the crate, hence why I'm opening an issue to ask for help instead of submitting a PR on this fairly simple change.Is it blocking?
No. It's easy to work-around, just overly complex and poor performance.
Describe alternatives you've considered
I'd considered a a
DereforAsReftrait as a way to get a&Uuidthat references the interior Bytes, if you want to avoid changing ownership of those Bytes, and it'd be easy enough to.to_ownedor.clonethat if you want. It'd also make it easy to write generics that takeDeref<Target = Uuid>orAsRef<Uuid>, so you could pass a Uuid, Simple, Hyphenated, or Urn to them and they'd all work the same way. AnInto<Uuid>would be nice for similar reasons. My point against this is that a[u8; 16]canCopyjust fine, as it's only 2-words long.Hi @jkoudys! 👋
This seems like a reasonable addition to me! I'd happily accept a range of trait impls on the adapters:
From<Adapter> for UuidAsRef<Uuid> for AdapterBorrow<Uuid> for AdapterClone+Copy+PartialEq+Eq+PartialOrd+Ord+HashDerefthough sinceAdapters aren't smart pointersAdapter::into_innermethod that takesselfand returns aUuid