prefix_id

Crates.ioprefix_id
lib.rsprefix_id
version1.0.2
sourcesrc
created_at2024-06-09 02:02:11.744183
updated_at2024-08-12 00:56:00.025057
descriptionA library for generating unique IDs nano ids with a prefix.
homepage
repositoryhttps://github.com/DevSlashRichie/prefix_id
max_upload_size
id1266125
size22,182
Ricardo (DevSlashRichie)

documentation

README

prefix_id

All the magic from nanoid but with a prefix

Inspired by nanoid

Docs.rs docs Crates.io version Download

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.0
Commit count: 6

cargo fmt