39 lines
844 B
Rust
39 lines
844 B
Rust
pub(super) struct FqnContext {
|
|
stack: Vec<String>,
|
|
}
|
|
|
|
impl FqnContext {
|
|
pub fn new() -> Self {
|
|
FqnContext { stack: Vec::new() }
|
|
}
|
|
|
|
pub fn push(&mut self, name: &str) {
|
|
self.stack.push(name.to_string());
|
|
}
|
|
|
|
pub fn pop(&mut self) {
|
|
self.stack.pop();
|
|
}
|
|
|
|
pub fn current(&self) -> String {
|
|
let mut acc = String::new();
|
|
for (i, name) in self.stack.iter().enumerate() {
|
|
acc.push_str(name);
|
|
if i != self.stack.len() - 1 {
|
|
acc.push_str("::")
|
|
}
|
|
}
|
|
acc
|
|
}
|
|
|
|
pub fn resolve(&self, name: &str) -> String {
|
|
let mut acc = String::new();
|
|
if !self.stack.is_empty() {
|
|
acc.push_str(&self.current());
|
|
acc.push_str("::");
|
|
}
|
|
acc.push_str(name);
|
|
acc
|
|
}
|
|
}
|