1pub fn module_feature(path: &str) -> Option<&'static str> {
6 MODULE_FEATURES
7 .iter()
8 .filter(|(prefix, _)| path == *prefix || path.starts_with(&format!("{prefix}::")))
9 .max_by_key(|(prefix, _)| prefix.len())
10 .map(|&(_, feature)| feature)
11}
12
13const MODULE_FEATURES: &[(&str, &str)] = &[
15 ("std::cli", "cli"),
16 ("std::datetime", "datetime"),
17 ("std::decimal", "rust_decimal"),
18 ("std::env", "env"),
19 ("std::fs", "fs"),
20 ("std::gui", "gui"),
21 ("std::hash", "hash"),
22 ("std::http", "http"),
23 ("std::json", "json"),
24 ("std::log", "log"),
25 ("std::net", "net"),
26 ("std::process", "process"),
27 ("std::ptr", "ptr"),
28 ("std::random", "random"),
29 ("std::regex", "regex"),
30 ("std::thread", "thread"),
31 ("std::time", "time"),
32 ("std::re::asm", "re-asm"),
33 ("std::re::dotnet", "re-dotnet"),
34 ("std::re::dotnet::il2cpp", "re-dotnet-il2cpp"),
35 ("std::re::dotnet::runtime", "re-dotnet-runtime"),
36 ("std::re::elf", "re-image"),
37 ("std::re::pe", "re-image"),
38 ("std::re::proc", "re-proc"),
39];
40
41#[cfg(test)]
42mod tests {
43 use super::module_feature;
44
45 #[test]
46 fn the_longest_prefix_wins() {
47 assert_eq!(module_feature("std::fs"), Some("fs"));
48 assert_eq!(module_feature("std::re::dotnet::sig"), Some("re-dotnet"));
49 assert_eq!(
50 module_feature("std::re::dotnet::il2cpp::binary"),
51 Some("re-dotnet-il2cpp")
52 );
53 assert_eq!(module_feature("std::fmt"), None);
54 assert_eq!(module_feature("std::fsx"), None);
55 }
56}