basic/
basic.rs

1use short_id::{id, short_id, ShortId};
2#[cfg(feature = "std")]
3use short_id::{ordered_id, short_id_ordered};
4
5fn main() {
6    println!("=== Functions ===");
7
8    // Generate a random ID using the function
9    let random_id = short_id();
10    println!("short_id():         {random_id}");
11
12    // Generate a time-ordered ID using the function
13    #[cfg(feature = "std")]
14    {
15        let ordered = short_id_ordered();
16        println!("short_id_ordered(): {ordered}");
17    }
18
19    println!("\n=== Macros ===");
20
21    // Generate IDs using macros (convenient shorthand)
22    let macro_id = id!();
23    println!("id!():              {macro_id}");
24
25    #[cfg(feature = "std")]
26    {
27        let macro_ordered = ordered_id!();
28        println!("ordered_id!():      {macro_ordered}");
29    }
30
31    println!("\n=== Typed Wrapper ===");
32
33    // Generate IDs using the ShortId type
34    let typed_random = ShortId::random();
35    println!("ShortId::random():  {typed_random}");
36
37    #[cfg(feature = "std")]
38    {
39        let typed_ordered = ShortId::ordered();
40        println!("ShortId::ordered(): {typed_ordered}");
41    }
42
43    // Demonstrate type conversions
44    let s: String = typed_random.clone().into();
45    println!("\nConverted to String: {s}");
46    println!("Using as_str():      {}", typed_random.as_str());
47    println!("Using AsRef<str>:    {}", typed_random.as_ref());
48}