dtz_identifier/
lib.rs

1mod apikey_id;
2mod case_id;
3mod context_id;
4mod execution_id;
5mod feed_id;
6mod identity_id;
7mod job_id;
8mod object_id;
9mod role_id;
10mod service_id;
11mod task_id;
12
13pub use apikey_id::*;
14pub use case_id::*;
15pub use context_id::*;
16pub use execution_id::*;
17pub use feed_id::*;
18pub use identity_id::*;
19pub use job_id::*;
20pub use object_id::*;
21pub use role_id::*;
22pub use service_id::*;
23pub use task_id::*;
24
25fn generate_internal_id(length: usize) -> String {
26    use rand::prelude::*;
27    let mut rng = rand::rng();
28    // generate the first non-numeric character
29    let first_char: char = loop {
30        let c: char = rng.sample(rand::distr::Alphanumeric) as char;
31        if c.is_alphabetic() {
32            break c;
33        }
34    };
35    // generate DEFAULT_LENGTH-1 random alphanumeric characters
36    let mut id: Vec<char> = (0..length - 1)
37        .map(|_| rng.sample(rand::distr::Alphanumeric) as char)
38        .collect();
39    id.insert(0, first_char);
40    id.into_iter().collect::<String>().to_lowercase()
41}
42
43#[test]
44fn test_generate_id_string() {
45    let id = generate_internal_id(8);
46    println!("id: {}", id);
47    assert_eq!(id.len(), 8);
48    let c = id.chars().next().unwrap();
49    assert!(c.is_alphabetic());
50}