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