cargo/util/
restricted_names.rs
1use std::path::Path;
4
5pub fn is_non_ascii_name(name: &str) -> bool {
7 name.chars().any(|ch| ch > '\x7f')
8}
9
10pub fn is_keyword(name: &str) -> bool {
12 [
14 "Self", "abstract", "as", "async", "await", "become", "box", "break", "const", "continue",
15 "crate", "do", "dyn", "else", "enum", "extern", "false", "final", "fn", "for", "if",
16 "impl", "in", "let", "loop", "macro", "match", "mod", "move", "mut", "override", "priv",
17 "pub", "ref", "return", "self", "static", "struct", "super", "trait", "true", "try",
18 "type", "typeof", "unsafe", "unsized", "use", "virtual", "where", "while", "yield",
19 ]
20 .contains(&name)
21}
22
23pub fn is_windows_reserved(name: &str) -> bool {
25 [
26 "con", "prn", "aux", "nul", "com1", "com2", "com3", "com4", "com5", "com6", "com7", "com8",
27 "com9", "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9",
28 ]
29 .contains(&name.to_ascii_lowercase().as_str())
30}
31
32pub fn is_conflicting_artifact_name(name: &str) -> bool {
34 ["deps", "examples", "build", "incremental"].contains(&name)
35}
36
37pub fn is_windows_reserved_path(path: &Path) -> bool {
39 path.iter()
40 .filter_map(|component| component.to_str())
41 .any(|component| {
42 let stem = component.split('.').next().unwrap();
43 is_windows_reserved(stem)
44 })
45}
46
47pub fn is_glob_pattern<T: AsRef<str>>(name: T) -> bool {
49 name.as_ref().contains(&['*', '?', '[', ']'][..])
50}