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

NonZeroUuid #770

Open
rick-de-water opened this issue Sep 30, 2024 · 2 comments
Open

NonZeroUuid #770

rick-de-water opened this issue Sep 30, 2024 · 2 comments

Comments

@rick-de-water
Copy link

rick-de-water commented Sep 30, 2024

Is there a NonZeroUuid type, or has one been considered, similar to the other NonZero types, such that the following is true?

assert_eq!(std::mem::size_of::<Option<NonZeroUuid>>(), std::mem::size_of::<Uuid>());
@KodrAus
Copy link
Member

KodrAus commented Oct 6, 2024

Hi @rick-de-water 👋 A UUID with all zeroes is actually a valid value, it’s called the nil UUID.

Are you looking at Option<Uuid> to avoid serializing them if they’re nil?

@rick-de-water
Copy link
Author

Of course, and an integer with a value of zero is also valid. There are however situation where you know that you will never use that value, and you can allow the compiler to do niche optimization if you inform it. This is what happens with the NonZero types, and of course with references, since they also cannot be null.

Its actually quite common to have domain models that do not have NIL UUIDs, since they get generated at the moment of creation and never change. Having NonZeroUuids (or NonNilUuids if you want to be specific) can have a definite impact on the memory usage of a program.

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

No branches or pull requests

2 participants