You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 Display and FromStr formats, 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:
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.
The text was updated successfully, but these errors were encountered:
sunshowers
changed the title
Tagged UUID support
Tagged UUID support (serialization format includes tag name)
Feb 1, 2024
With something like a typed UUID format, there are several things to consider:
Display
andFromStr
formats, which are implicitly used in a lot of places (I'd like to retain the property that they're reversible.)TypedUuid
only changes 1, leaving 2-4 untouched (4 isn't implemented in this crate -- but in omicron we define aDbTypedUuid
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 aTypedUuid
:But the implementations for 2 and/or 3 above are different and also include
T::tag()
. For example, aTaggedUuid<SledKind>
could be serialized assled:50a03aaf-8b59-4f4b-a9dc-da6ff6c570be
rather than just50a03aaf-8b59-4f4b-a9dc-da6ff6c570be
.Then, we can allow bidirectional conversions between
TypedUuid
andTaggedUuid
.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.
The text was updated successfully, but these errors were encountered: