-
Notifications
You must be signed in to change notification settings - Fork 479
/
item.rs
72 lines (64 loc) · 1.57 KB
/
item.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use super::*;
/// A single top-level item
#[derive(Debug, Clone)]
pub(crate) enum Item<'src> {
Alias(Alias<'src, Name<'src>>),
Assignment(Assignment<'src>),
Comment(&'src str),
Import {
absolute: Option<PathBuf>,
optional: bool,
path: Token<'src>,
relative: StringLiteral<'src>,
},
Module {
attributes: BTreeSet<Attribute<'src>>,
absolute: Option<PathBuf>,
doc: Option<&'src str>,
name: Name<'src>,
optional: bool,
relative: Option<StringLiteral<'src>>,
},
Recipe(UnresolvedRecipe<'src>),
Set(Set<'src>),
Unexport {
name: Name<'src>,
},
}
impl<'src> Display for Item<'src> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
Self::Alias(alias) => write!(f, "{alias}"),
Self::Assignment(assignment) => write!(f, "{assignment}"),
Self::Comment(comment) => write!(f, "{comment}"),
Self::Import {
relative, optional, ..
} => {
write!(f, "import")?;
if *optional {
write!(f, "?")?;
}
write!(f, " {relative}")
}
Self::Module {
name,
relative,
optional,
..
} => {
write!(f, "mod")?;
if *optional {
write!(f, "?")?;
}
write!(f, " {name}")?;
if let Some(path) = relative {
write!(f, " {path}")?;
}
Ok(())
}
Self::Recipe(recipe) => write!(f, "{}", recipe.color_display(Color::never())),
Self::Set(set) => write!(f, "{set}"),
Self::Unexport { name } => write!(f, "unexport {name}"),
}
}
}