newtype-uuid
A newtype wrapper around Uuid.
Motivation
Many large systems use UUIDs as unique identifiers for various entities. However, the Uuid
type does not carry information about the kind of entity it identifies, which can lead to mixing
up different types of UUIDs at runtime.
This crate provides a wrapper type around Uuid that allows you to specify the kind of entity
the UUID identifies.
Example
use ;
// First, define a type that represents the kind of UUID this is.
// Now, a UUID can be created with this kind.
let uuid: = "dffc3068-1cd6-47d5-b2f3-636b41b07084".parse.unwrap;
// The Display (and therefore ToString) impls still show the same value.
assert_eq!;
// The Debug impl will show the tag as well.
assert_eq!;
Implementations
In general, TypedUuid uses the same wire and serialization formats as Uuid. This means
that data on the wire does not change; TypedUuid is intended to be helpful within Rust code,
not across serialization boundaries.
- The
DisplayandFromStrimpls are forwarded to the underlyingUuid. - If the
serdefeature is enabled,TypedUuidwill serialize and deserialize using the same format asUuid. - If the
schemars08feature is enabled,TypedUuidwill implementJsonSchemaif the correspondingTypedUuidKindimplementsJsonSchema.
To abstract over typed and untyped UUIDs, the GenericUuid trait is provided. This trait also
permits conversions between typed and untyped UUIDs.
Dependencies
- The only required dependency is the
uuidcrate. Optional features may add further dependencies.
Features
default: Enables default features in the uuid crate.std: Enables the use of the standard library. Enabled by default.serde: Enables serialization and deserialization support via Serde. Not enabled by default.v4: Enables thenew_v4method for generating UUIDs. Not enabled by default.schemars08: Enables support for generating JSON schemas via schemars 0.8. Not enabled by default.
Minimum supported Rust version (MSRV)
The MSRV of this crate is Rust 1.60. In general, this crate will follow the MSRV of the
underlying uuid crate.
License
This project is available under the terms of either the Apache 2.0 license or the MIT license.