Skip to main content

teaql_tool_std/
id.rs

1use nanoid::nanoid;
2use ulid::Ulid;
3use uuid::Uuid;
4
5pub struct IdTool;
6
7impl IdTool {
8    pub fn new() -> Self {
9        Self
10    }
11
12    pub fn uuid(&self) -> String {
13        Uuid::new_v4().to_string()
14    }
15
16    pub fn uuid_v7(&self) -> String {
17        Uuid::now_v7().to_string()
18    }
19
20    pub fn ulid(&self) -> String {
21        Ulid::new().to_string()
22    }
23
24    pub fn nanoid(&self) -> String {
25        nanoid!()
26    }
27
28    pub fn with_prefix(&self, prefix: &str) -> String {
29        format!("{}_{}", prefix, self.nanoid())
30    }
31}
32
33impl Default for IdTool {
34    fn default() -> Self {
35        Self::new()
36    }
37}