# typed-uuid [![Latest Version]][crates.io] [![Docs]][docs.rs] [Latest Version]: https://img.shields.io/crates/v/typed-uuid [crates.io]: https://crates.io/crates/typed-uuid [Docs]: https://docs.rs/typed-uuid/badge.svg [docs.rs]: https://docs.rs/typed-uuid `Id` is a typed wrapper around a `uuid::Uuid`. Use it to add type safety and prevent confusion between different kinds of Uuid. ## Example 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 = typed_uuid::Id; struct Relation { user: Id, role: Id, } ``` `Id`s with different `T` parameter types are incompatible, and cannot be compared. Attempting to assign an `Id` to a variable of type `Id` is a compilation error. ```rust let user = Id::::new(); let role = Id::::new(); // Compilation fails here, can't compare Id and Id assert_eq!(user, role); ``` But `Id`s of the same type work: ```rust let mut first = Id::::new(); let second = Id::::new(); first = second; assert_eq!(first, second); ``` ## Usage When depending on this library, you need to explicitly select the versions of the uuid, you will be using, as well as optionally `serde` support: ```toml [dependencies.typed-uuid] version = "*" default-features = false features = ["v4", "serde"] ```