Crates.io | crockford-uuid |
lib.rs | crockford-uuid |
version | 0.1.2 |
source | src |
created_at | 2023-05-27 09:58:45.880973 |
updated_at | 2023-05-27 10:38:07.009749 |
description | A library to generate and parse Crockford Base32 Identifiers. |
homepage | https://github.com/AdeThorMiwa/crockford-uuid |
repository | https://github.com/AdeThorMiwa/crockford-uuid |
max_upload_size | |
id | 875890 |
size | 11,651 |
crockford-uuid
Here's an example of a crockford-uuid:
4s0y2vz7sf4vghnznytz9gvq6
A crockford-uuid Uuid is a unique 120-bit value, stored as 15 bytes identifier, and a fixed number checksum character derived from the identifier for value's integrity check.
The uniqueness property is not strictly guaranteed, however for all practical purposes, it can be assumed that an unintentional collision would be extremely unlikely as the 120 bit key space is about the same size as the number of bacterial cells in existence on the planet. :)
Add the following to your Cargo.toml
:
crockford-uuid = "0.1.2"
When you want a identifier, you can generate one:
use crockford-uuid::Uuid;
let id = Uuid::new();
If you have a crockford-uuid value, you can use its string literal, BigUint and Bytes values inline:
use uuid::Uuid;
const from_string_lit: Uuid = "4s0y2vz7sf4vghnznytz9gvq6".try_into().unwrap();
const from_big_uint: Uuid = BigUint::parse_bytes(b"471569087780948647371060810118848519319753452797", 10).unwrap().try_into().unwrap();
You can also convert crockford-uuid to be used as a string literal, BigUint, Vec<u8>
(Bytes)
const to_str = Uuid::to_string();
const to_big_uint: BigUint = Uuid::new().into();
const to_vec: Vec<u8> = Uuid::new().into();
For more details on using crockford-uuid
, see the library documentation.
https://learning.oreilly.com/library/view/api-design-patterns/9781617295850/OEBPS/Text/06.htm#:-:text=6.3.3 https://www.crockford.com/base32.html