-
Notifications
You must be signed in to change notification settings - Fork 197
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
feat: Add NonZeroUuid
type for optimized Option<Uuid>
representation
#779
Conversation
This commit introduces a new `NonZeroUuid` type that wraps a `Uuid` and guarantees that it is not the nil UUID. This allows for a more memory-efficient representation of `Option<Uuid>`, as `Option<NonZeroUuid>` takes up the same space as `Uuid`. This change improves the memory efficiency of representing optional UUIDs and provides a more convenient way to work with non-nil UUIDs. fixes: uuid-rs#770
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.
Thanks for the PR @ab22593k! I've left a few comments to get started.
In addition to this, I think we should consider other trait implementations on this type:
Debug
andDisplay
that are based on the underlyingUuid
serde::Serialize
and other external libraries thatuuid
optionally depends on
I'd also like to set the expectation that we won't be adding any methods to NonNilUuid
besides construction from Uuid
s and conversions to Uuid
s, otherwise it'll end up duplicating Uuid
s entire API on it.
It's also worth pointing out that the conversion will always succeed for any Uuid
created via the Uuid::new_v*
methods, since they set version/variant bits they're never nil.
PTL @KodrAus |
It looks like we've got some build failures with different feature combinations:
|
We should use |
Thanks for working through this @ab22593k! I just had a few comments, but I think this is getting close now. |
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.
Thanks @ab22593k! This looks good to me
Bumps uuid from 1.11.1 to 1.12.0. Release notes Sourced from uuid's releases. 1.12.0 What's Changed feat: Add NonZeroUuid type for optimized Option<Uuid> representation by @ab22593k in uuid-rs/uuid#779 Finalize NonNilUuid by @KodrAus in uuid-rs/uuid#783 Prepare for 1.12.0 release by @KodrAus in uuid-rs/uuid#784 New Contributors @ab22593k made their first contribution in uuid-rs/uuid#779 Full Changelog: uuid-rs/[email protected] Commits c5f1d02 Merge pull request #784 from uuid-rs/cargo/1.12.0 4cfbd83 fix deprecation versions 8f76175 prepare for 1.12.0 release 358eb34 Merge pull request #783 from uuid-rs/feat/non-nil 6c5099e also remove borsh from NonNilUuid for now b12c690 fix up non nil docs 38df005 remove zerocopy from NonNilUuid for now 4021daa fix up zerocopy derives f570b57 support equality between NonNilUuid and Uuid 4ffd872 add a few missing derives Additional commits viewable in compare view Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase. Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: @dependabot rebase will rebase this PR @dependabot recreate will recreate this PR, overwriting any edits that have been made to it @dependabot merge will merge this PR after your CI passes on it @dependabot squash and merge will squash and merge this PR after your CI passes on it @dependabot cancel merge will cancel a previously requested merge and block automerging @dependabot reopen will reopen this PR if it is closed @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually @dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
This commit introduces a new
NonZeroUuid
type that wraps aUuid
and guarantees that it is not the nil UUID. This allows for a more memory-efficient representation ofOption<Uuid>
, asOption<NonZeroUuid>
takes up the same space asUuid
.This change improves the memory efficiency of representing optional UUIDs and provides a more convenient way to work with non-nil UUIDs.
fixes: #770