Skip to content

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

@sunshowers

Description

@sunshowers

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions