ig_client/utils/id.rs
1/// Generates a unique identifier as an optional `String`.
2///
3/// This function creates a 30-character long unique identifier composed of
4/// uppercase English letters (`A-Z`) and numbers (`0-9`) using the `nanoid`
5/// library. The generated identifier is securely random and designed to be
6/// collision-resistant.
7///
8/// # Returns
9/// - `Some(String)`: A generated identifier as a `String` if successful.
10/// - `None`: This function is designed to always return `Some`, but this is
11/// wrapped in an `Option` for potential extension or compatibility with
12/// other code.
13///
14/// # Examples
15/// ```
16/// use ig_client::utils::id::get_id;
17/// let unique_id = get_id();
18/// if let Some(id) = unique_id {
19/// println!("Generated ID: {}", id);
20/// }
21/// ```
22///
23/// # Dependencies
24/// - This function relies on the `nanoid` crate, which must be added to your
25/// project dependencies in `Cargo.toml`:
26///
27/// ```toml
28/// [dependencies]
29/// nanoid = "0.4"
30/// ```
31pub fn get_id() -> Option<String> {
32 let alphabet: Vec<char> = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".chars().collect();
33 Some(nanoid::nanoid!(30, &alphabet))
34}