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

Tagged UUID support (serialization format includes tag name) #8

Open
sunshowers opened this issue Feb 1, 2024 · 0 comments
Open

Tagged UUID support (serialization format includes tag name) #8

sunshowers opened this issue Feb 1, 2024 · 0 comments

Comments

@sunshowers
Copy link
Collaborator

sunshowers commented Feb 1, 2024

With something like a typed UUID format, there are several things to consider:

  1. The types within Rust code
  2. The serde serialization format used for our external APIs
  3. The Display and FromStr formats, which are implicitly used in a lot of places (I'd like to retain the property that they're reversible.)
  4. The database storage format.

TypedUuid only changes 1, leaving 2-4 untouched (4 isn't implemented in this crate -- but in omicron we define a DbTypedUuid type which follows the same property).

However, there are good reasons to change 2 and 3 as well, primarily around ensuring that when types are serialized we aren't mixing them up. One way is to define another type called a TaggedUuid. The definition is the same as that of a TypedUuid:

struct TaggedUuid<T: TypedUuidKind> {
    uuid: Uuid,
    marker: PhantomData<T>,
}

But the implementations for 2 and/or 3 above are different and also include T::tag(). For example, a TaggedUuid<SledKind> could be serialized as sled:50a03aaf-8b59-4f4b-a9dc-da6ff6c570be rather than just 50a03aaf-8b59-4f4b-a9dc-da6ff6c570be.

Then, we can allow bidirectional conversions between TypedUuid and TaggedUuid.

At that point, users of the crate can specify what kind of format they want by switching up the types, and make the conversion an explicit, gradual process.

@sunshowers sunshowers changed the title Tagged UUID support Tagged UUID support (serialization format includes tag name) Feb 1, 2024
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

1 participant