use entid::{Prefix, UlidEntityId, UuidEntityId};
#[derive(Debug)]
struct User;
impl Prefix for User {
fn prefix() -> &'static str {
"user"
}
}
#[derive(Debug)]
struct Post;
impl Prefix for Post {
fn prefix() -> &'static str {
"post"
}
fn delimiter() -> &'static str {
"-"
}
}
#[derive(Debug)]
struct Comment;
impl Prefix for Comment {
fn prefix() -> &'static str {
"comment"
}
}
fn main() {
let user_id = UuidEntityId::<User>::generate();
println!("User ID: {}", user_id);
let post_id = UlidEntityId::<Post>::generate();
println!("Post ID: {}", post_id);
let comment_id_str = format!("comment_{}", uuid::Uuid::new_v4());
let comment_id = UuidEntityId::<Comment>::new(&comment_id_str).unwrap();
println!("Comment ID: {}", comment_id);
assert!(user_id.as_str().starts_with("user_"));
assert!(post_id.as_str().starts_with("post-"));
assert!(comment_id.as_str().starts_with("comment_"));
}