-
Notifications
You must be signed in to change notification settings - Fork 10
Description
With something like a typed UUID format, there are several things to consider:
- The types within Rust code
- The serde serialization format used for our external APIs
- The
DisplayandFromStrformats, which are implicitly used in a lot of places (I'd like to retain the property that they're reversible.) - 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.