Id
is a typed wrapper around a uuid::Uuid
.
Use it to add type safety and prevent confusion between different kinds of Uuid.
Represent different types of Id to prevent mixups or invalid states. If describing
a unique resource's relationship to another, for example the Role
a User
has,
the relationship can be expressed as follows:
```rust
// Subtype the Id type to specify the version of the Id, instead
// of repeating yourself everywhere.
type Id
struct Relation {
user: Id
Ids with different
T` parameter types are incompatible, and cannot be compared.
Attempting to assign an Id<User>
to a variable of type Id<Role>
is a compilation error.
```rust
let user = Id::
// Compilation fails here, can't compare Id
But Id
s of the same type work:
```rust
let mut first = Id::
first = second; assert_eq!(first, second); ```
When depending on this library, you should probably choose to disable all default features, since all Uuid versions up to and including v5 are enabled by default,
but you probably only want to use one type:
toml
[dependencies.typed-uuid]
version = "*"
default-features = false
features = ["v4", "serde"]