1pub fn uuid_simple() -> String {
16 use std::time::{SystemTime, UNIX_EPOCH};
17 let duration = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
18 format!("{}{}", duration.as_secs(), duration.subsec_nanos())
19}
20
21pub fn truncate_path(path: &str, max_len: usize) -> String {
36 if path.len() <= max_len {
37 path.to_string()
38 } else {
39 format!("...{}", &path[path.len() - max_len + 3..])
40 }
41}
42
43#[cfg(test)]
44mod tests {
45 use super::*;
46
47 #[test]
48 fn test_uuid_simple_not_empty() {
49 let id = uuid_simple();
50 assert!(!id.is_empty());
51 }
52
53 #[test]
54 fn test_uuid_simple_unique() {
55 let id1 = uuid_simple();
56 std::thread::sleep(std::time::Duration::from_nanos(1));
57 let id2 = uuid_simple();
58 assert_ne!(id1, id2);
59 }
60
61 #[test]
62 fn test_truncate_path_short() {
63 let path = "C:\\short";
64 let result = truncate_path(path, 20);
65 assert_eq!(result, path);
66 }
67
68 #[test]
69 fn test_truncate_path_long() {
70 let path = "C:\\Users\\Name\\Very\\Long\\Path\\To\\Project";
71 let result = truncate_path(path, 20);
72 assert!(result.starts_with("..."));
73 assert!(result.len() <= 20);
74 }
75}