A type-safe, K-sortable, globally unique identifier.
Typed implementation of https://github.com/jetpack-io/typeid in Rust.
This is the intended happy path. Using a StaticType implementation, you ensure that the ID being parsed is of the intended type.
```rust use typesafeid::{StaticType, TypeSafeId};
struct User;
impl StaticType for User { // must be lowercase ascii [a-z] only const TYPE: &'static str = "user"; }
// type alias for your custom typed id
type UserId = TypeSafeId
let user_id1 = UserId::new();
let user_id2 = UserId::new();
let uid1 = userid1.tostring(); let uid2 = userid2.tostring(); dbg!(&uid1, &uid2); assert!(uid2 > uid1, "type safe IDs are ordered");
let userid3: UserId = uid1.parse().expect("invalid user id"); let userid4: UserId = uid2.parse().expect("invalid user id");
asserteq!(userid1.uuid(), userid3.uuid(), "round trip works"); asserteq!(userid2.uuid(), userid4.uuid(), "round trip works"); ```
If you can't know what the prefix will be, you can use the DynamicType prefix.
```rust use typesafeid::{DynamicType, TypeSafeId};
let id: TypeSafeId
asserteq!(id.typeprefix(), "prefix"); assert_eq!(id.uuid(), uuid::uuid!("0188bac7-4afa-78aa-bc3b-bd1eef28d881")); ```