codegraph_parser_api/relationships/
imports.rs

1use serde::{Deserialize, Serialize};
2
3/// Represents an import/dependency relationship
4#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
5pub struct ImportRelation {
6    /// Importing module
7    pub importer: String,
8
9    /// Imported module
10    pub imported: String,
11
12    /// Specific symbols imported (empty = whole module)
13    pub symbols: Vec<String>,
14
15    /// Is this a wildcard import?
16    pub is_wildcard: bool,
17
18    /// Import alias (if any)
19    pub alias: Option<String>,
20}
21
22impl ImportRelation {
23    pub fn new(importer: impl Into<String>, imported: impl Into<String>) -> Self {
24        Self {
25            importer: importer.into(),
26            imported: imported.into(),
27            symbols: Vec::new(),
28            is_wildcard: false,
29            alias: None,
30        }
31    }
32
33    pub fn with_symbols(mut self, symbols: Vec<String>) -> Self {
34        self.symbols = symbols;
35        self
36    }
37
38    pub fn wildcard(mut self) -> Self {
39        self.is_wildcard = true;
40        self
41    }
42
43    pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
44        self.alias = Some(alias.into());
45        self
46    }
47}