pub struct Import {
pub name: String,
pub path: Vec<String>,
pub depth: usize,
pub line: usize,
}Expand description
A name brought into a file’s scope, and the module path it came from.
Recorded as a lexical scoping signal, not a resolved path (#252).
use crate::model::Symbol says that in this file Symbol came from a module
called model, which is enough to prefer a definition under model.rs over
a same-named one elsewhere — without needing to know where a crate root is,
and so without extraction depending on any file but this one (ADR 0012).
Relative markers (crate, self, super, ., ..) are stripped: they
position the path rather than naming a module.
Fields§
§name: StringThe name as this file will write it — the alias when there is one.
Empty when the import brings in a whole file rather than one name: a
C/C++ #include names a path, not a symbol (#267). Test that with
brings_whole_file rather than comparing
against the empty string, so the intent is visible at the call site.
path: Vec<String>The module path segments before the name, outermost first.
depth: usizeHow many dots a relative import leads with; 0 when absolute.
A Python relative import is the one module path resolvable with no
project root at all: from ..pkg import X means “my parent package,
then pkg”, which is arithmetic on the referencing file’s own path.
Dropping the dots threw that away and left the module to be matched as a
free-floating suffix against every candidate (#261).
Omitted from the serialized slice when zero, so a file with only absolute imports keeps a byte-identical slice.
line: usizeImplementations§
Source§impl Import
impl Import
Sourcepub fn brings_whole_file(&self) -> bool
pub fn brings_whole_file(&self) -> bool
Whether this import brings in a whole file rather than one name.
A #include names a path — every declaration in that file becomes
visible — so it has no single name to key on the way every other import
does. Resolution matches it by path instead (#267).