Skip to content
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

Allow access of inner Uuid for Hyphenated, Simple, Urn #482

Closed
jkoudys opened this issue Jul 28, 2020 · 1 comment · Fixed by #511
Closed

Allow access of inner Uuid for Hyphenated, Simple, Urn #482

jkoudys opened this issue Jul 28, 2020 · 1 comment · Fixed by #511

Comments

@jkoudys
Copy link

jkoudys commented Jul 28, 2020

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: launchbadge/sqlx#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 Uuid would 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 Deref or AsRef trait as a way to get a &Uuid that references the interior Bytes, if you want to avoid changing ownership of those Bytes, and it'd be easy enough to .to_owned or .clone that if you want. It'd also make it easy to write generics that take Deref<Target = Uuid> or AsRef<Uuid>, so you could pass a Uuid, Simple, Hyphenated, or Urn to them and they'd all work the same way. An Into<Uuid> would be nice for similar reasons. My point against this is that a [u8; 16] can Copy just fine, as it's only 2-words long.

@KodrAus
Copy link
Member

KodrAus commented Dec 21, 2020

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 Uuid
  • AsRef<Uuid> for Adapter
  • Borrow<Uuid> for Adapter
  • Clone + Copy + PartialEq + Eq + PartialOrd + Ord + Hash
  • not Deref though since Adapters aren't smart pointers
  • An inherent Adapter::into_inner method that takes self and returns a Uuid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants