Crates.io | typeid_suffix |
lib.rs | typeid_suffix |
version | 1.0.2-beta.1 |
source | src |
created_at | 2024-07-11 09:47:09.362657 |
updated_at | 2024-07-13 04:32:52.332271 |
description | A Rust library that implements the UUID suffix part of the `TypeId`Specification |
homepage | |
repository | https://github.com/GovCraft/typeid_suffix |
max_upload_size | |
id | 1299357 |
size | 45,098 |
TypeId
SuffixA Rust library that implements the suffix portion of the TypeID Specification. It provides functionality to work with TypeId
suffixes, which are base32-encoded representations of UUIDs used in the TypeId
system.
Combined with the TypeIdPrefix crate to comprise the mti (Magic Type Id) crate.
Use the mti (Magic Type Id) crate for a holistic implementation of the TypeID specification.
UUIDv7
and other UUID versions.TypeId
suffixes.TypeId
suffixes and UUIDs.tracing
crate for logging (optional feature).Add this to your Cargo.toml
:
[dependencies]
typeid_suffix = "1.0.2-beta.1"
To enable optional features:
[dependencies]
typeid_suffix = { version = "1.0.2-beta.1", features = ["instrument"] }
use std::str::FromStr;
use typeid_suffix::prelude::*;
use uuid::Uuid;
fn main() {
// Create a `TypeId`suffix from a `UUIDv7`
let uuid = Uuid::now_v7();
let suffix = TypeIdSuffix::new(uuid).expect("Valid `UUIDv7`");
println!("TypeID suffix: {}", suffix);
// Parse a `TypeId`suffix from a string
let parsed_suffix = TypeIdSuffix::from_str("01h455vb4pex5vsknk084sn02q").expect("Valid suffix");
// Convert back to a UUID
let recovered_uuid: Uuid = suffix.try_into().expect("Valid UUID");
assert_eq!(uuid, recovered_uuid);
}
use typeid_suffix::prelude::*;
use uuid::Uuid;
fn main() {
let uuid = Uuid::new_v4();
let suffix = TypeIdSuffix::new(uuid).expect("Valid UUID");
println!("TypeID suffix for UUIDv4: {}", suffix);
}
The crate provides detailed error types for various failure cases:
use typeid_suffix::prelude::*;
use std::str::FromStr;
fn main() {
let result = TypeIdSuffix::from_str("invalid_suffix");
match result {
Ok(_) => println!("Valid suffix"),
Err(e) => println!("Invalid suffix: {}", e),
}
}
When the instrument
feature is enabled, the crate will log operations using the tracing
crate:
[dependencies]
typeid_suffix = { version = "1.0.2-beta.1", features = ["instrument"] }
TypeId
suffixes as part of API responses or for resource identification.UUIDv7
-based TypeId
suffixes for time-ordered data.This crate has been thoroughly tested and verified:
proptest
These measures ensure that the crate behaves correctly and safely under various inputs and conditions.
This crate is guaranteed to compile on Rust 1.60.0 and later.
This project is licensed under either of
at your option.
Contributions are welcome! Please feel free to submit a Pull Request.
This crate implements a portion of the TypeID Specification created by Jetpack.io.