Crates.io | prefix_id |
lib.rs | prefix_id |
version | 1.0.2 |
source | src |
created_at | 2024-06-09 02:02:11.744183 |
updated_at | 2024-08-12 00:56:00.025057 |
description | A library for generating unique IDs nano ids with a prefix. |
homepage | |
repository | https://github.com/DevSlashRichie/prefix_id |
max_upload_size | |
id | 1266125 |
size | 22,182 |
All the magic from nanoid but with a prefix
Inspired by nanoid
cargo add prefix_id
create_id!(MyEntityId, "id");
let id = MyEntityId::new(); // => "id_1234567890avjfwdnfvqdp"
// then you can use the impl methods
id.as_str(); // => "id_1234567890avjfwdnfvqdp"
let my_string: String = id.into();
// you can also validate/convert it from string
let str = "id_1234567890avjfwdnfvqdp";
let id = MyEntityId::from_str(str).unwrap();
// you can optionally set the feature `serde` flag to serialize/deserialize
let serialized = serde_json::to_string(&id).unwrap();
let deserialized = serde_json::from_str::<MyEntityId>(&serialized).unwrap();