cargo_autodd/utils/
crate_utils.rs1use std::path::Path;
2
3pub fn is_hidden(path: &Path) -> bool {
5 path.components()
6 .any(|c| c.as_os_str().to_string_lossy().starts_with('.'))
7}
8
9pub fn is_std_crate(name: &str) -> bool {
11 let std_crates = [
12 "std",
14 "core",
15 "alloc",
16 "test",
17 "proc_macro",
18 "collections",
19 "String",
21 "Vec",
22 "HashMap",
23 "HashSet",
24 "BTreeMap",
25 "BTreeSet",
26 "PathBuf",
27 "Path",
28 "Result",
29 "Option",
30 "Box",
31 "Arc",
32 "Rc",
33 "Cell",
34 "RefCell",
35 "Mutex",
36 "RwLock",
37 ];
38 std_crates.contains(&name)
39 || name.starts_with("std::")
40 || name.starts_with("core::")
41 || name.starts_with("alloc::")
42}
43
44pub fn is_essential_dep(name: &str) -> bool {
46 let essential_deps = [
47 "serde",
48 "tokio",
49 "anyhow",
50 "thiserror",
51 "async-trait",
52 "futures",
53 ];
54 essential_deps.contains(&name)
55}
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_is_hidden() {
63 assert!(is_hidden(Path::new(".git")));
64 assert!(is_hidden(Path::new("/path/to/.hidden")));
65 assert!(!is_hidden(Path::new("visible")));
66 assert!(!is_hidden(Path::new("/path/to/visible")));
67 }
68
69 #[test]
70 fn test_is_std_crate() {
71 assert!(is_std_crate("std"));
73 assert!(is_std_crate("core"));
74 assert!(is_std_crate("alloc"));
75 assert!(is_std_crate("proc_macro"));
76
77 assert!(is_std_crate("String"));
79 assert!(is_std_crate("Vec"));
80 assert!(is_std_crate("HashMap"));
81
82 assert!(is_std_crate("std::collections"));
84 assert!(is_std_crate("core::mem"));
85 assert!(is_std_crate("alloc::vec"));
86
87 assert!(!is_std_crate("serde"));
89 assert!(!is_std_crate("tokio"));
90 assert!(!is_std_crate("rand")); assert!(!is_std_crate("libc")); assert!(!is_std_crate("custom_crate"));
93 }
94
95 #[test]
96 fn test_is_essential_dep() {
97 assert!(is_essential_dep("serde"));
98 assert!(is_essential_dep("tokio"));
99 assert!(!is_essential_dep("custom_crate"));
100 assert!(!is_essential_dep("std"));
101 }
102}