1use alloc::vec::Vec;
4use core::fmt::{self, Display};
5
6#[derive(Clone, Debug, PartialEq, Eq)]
8pub struct Symb<S> {
9 pub path: Vec<S>,
11 pub name: S,
13}
14
15impl<S> Symb<S> {
16 pub fn new(name: S) -> Self {
18 let path = Vec::new();
19 Self { path, name }
20 }
21
22 pub fn map<T>(self, f: impl Fn(S) -> T) -> Symb<T> {
24 Symb {
25 path: self.path.into_iter().map(&f).collect(),
26 name: f(self.name),
27 }
28 }
29
30 pub fn push(&mut self, name: S) {
33 self.path.push(core::mem::replace(&mut self.name, name));
34 }
35}
36
37impl<S: Display> Display for Symb<S> {
38 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
39 self.path.iter().try_for_each(|p| write!(f, "{}.", p))?;
40 self.name.fmt(f)
41 }
42}