gather_all_code_from_crates/
item_info.rs

1crate::ix!();
2
3#[derive(Debug, Clone)]
4pub enum ItemInfo {
5    Function(FunctionInfo),
6    Struct {
7        name: String,
8        attributes: Vec<String>,
9        is_public: bool,
10        signature: String,
11    },
12    Enum {
13        name: String,
14        attributes: Vec<String>,
15        is_public: bool,
16        signature: String,
17    },
18    TypeAlias {
19        name: String,
20        attributes: Vec<String>,
21        is_public: bool,
22        signature: String,
23    },
24    ImplBlock {
25        name: Option<String>,
26        attributes: Vec<String>,
27        is_public: bool,
28        // Impl blocks themselves might not have "names" in the same sense,
29        // but you might want to record their signature or generic params.
30        signature: String,
31        methods: Vec<FunctionInfo>,
32    },
33}
34
35pub fn deduplicate_items(items: Vec<ItemInfo>) -> Vec<ItemInfo> {
36    let mut seen_methods = std::collections::HashSet::new();
37
38    // First pass: collect all method names from impl blocks
39    for item in &items {
40        if let ItemInfo::ImplBlock { methods, .. } = item {
41            for m in methods {
42                seen_methods.insert(m.name().to_string());
43            }
44        }
45    }
46
47    // Second pass: filter out standalone functions that appear as methods in impl blocks
48    items.into_iter()
49        .filter(|item| {
50            match item {
51                ItemInfo::Function(f) => {
52                    // Keep this function only if it is not a method in an impl block
53                    !seen_methods.contains(f.name())
54                }
55                _ => true
56            }
57        })
58        .collect()
59}