3 stable releases
1.0.2 | Aug 12, 2024 |
---|---|
1.0.1 | Jun 9, 2024 |
#3 in #nanoid
11KB
235 lines
prefix_id
All the magic from nanoid but with a prefix
Inspired by nanoid
Installation
cargo add prefix_id
Usage
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();
License
Licensed under Apache License, Version 2.0Dependencies
~0.6–1.7MB
~35K SLoC