light_tool/
uuid.rs

1use crate::{random, timestamp, mac, md5};
2
3/// Generate uuid by random_str - timestamp - mac
4///
5/// # Example
6///
7/// ```no_run
8/// use light_tool::uuid;
9/// println!("uuid: {}", uuid::new())
10/// ```
11pub fn new() -> String {
12    let s =md5::str(format!("{}-{}-{}",  random::alpha_num(36),
13                            timestamp::nano_seconds(),
14                            mac::address().unwrap_or(timestamp::nano_seconds().to_string())));
15
16    format!("{}-{}-{}-{}-{}", &s[0..8], &s[8..12], &s[12..16], &s[16..20], &s[20..])
17}
18
19#[cfg(test)]
20mod tests {
21    use super::*;
22
23    #[test]
24    fn test_uuid() {
25        println!("uuid: {}", new());
26    }
27}