-
Notifications
You must be signed in to change notification settings - Fork 771
Expand file tree
/
Copy pathalias.rs
More file actions
55 lines (48 loc) · 1.26 KB
/
alias.rs
File metadata and controls
55 lines (48 loc) · 1.26 KB
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
use super::*;
/// An alias, e.g. `alias name := target`
#[derive(Debug, PartialEq, Clone, Serialize)]
pub(crate) struct Alias<'src, T = Arc<Recipe<'src>>> {
pub(crate) attributes: AttributeSet<'src>,
pub(crate) name: Name<'src>,
#[serde(
bound(serialize = "T: Keyed<'src>"),
serialize_with = "keyed::serialize"
)]
pub(crate) target: T,
}
impl<'src> Alias<'src, Namepath<'src>> {
pub(crate) fn resolve(self, target: Arc<Recipe<'src>>) -> Alias<'src> {
assert!(self.target.last().lexeme() == target.name());
Alias {
attributes: self.attributes,
name: self.name,
target,
}
}
}
impl Alias<'_> {
pub(crate) fn is_public(&self) -> bool {
!self.name.lexeme().starts_with('_')
&& !self.attributes.contains(AttributeDiscriminant::Private)
}
}
impl<'src, T> Keyed<'src> for Alias<'src, T> {
fn key(&self) -> &'src str {
self.name.lexeme()
}
}
impl<'src> Display for Alias<'src, Namepath<'src>> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "alias {} := {}", self.name.lexeme(), self.target)
}
}
impl Display for Alias<'_> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(
f,
"alias {} := {}",
self.name.lexeme(),
self.target.name.lexeme()
)
}
}