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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//! Build-specific `extra_hosts` values.
use super::Located;
use crate::source::SourceSpan;
/// Build-time host mappings with list and mapping syntax retained separately from service
/// [`super::ExtraHosts`].
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BuildExtraHosts {
/// Ordered raw string entries, including duplicates.
List {
/// The complete sequence span.
span: SourceSpan,
/// Raw host-mapping strings in authored order.
values: Vec<Located<String>>,
},
/// Ordered hostname entries with scalar or list addresses.
Map {
/// The complete mapping span.
span: SourceSpan,
/// Hostname entries in authored order.
entries: Vec<BuildExtraHostEntry>,
},
}
impl BuildExtraHosts {
/// Returns the complete collection span.
#[must_use]
pub const fn span(&self) -> SourceSpan {
match self {
Self::List { span, .. } | Self::Map { span, .. } => *span,
}
}
}
/// One mapping-form build host entry.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BuildExtraHostEntry {
hostname: Located<String>,
addresses: BuildExtraHostAddresses,
span: SourceSpan,
}
impl BuildExtraHostEntry {
pub(crate) const fn new(hostname: Located<String>, addresses: BuildExtraHostAddresses, span: SourceSpan) -> Self {
Self {
hostname,
addresses,
span,
}
}
/// Returns the raw hostname key and its source span.
#[must_use]
pub const fn hostname(&self) -> &Located<String> {
&self.hostname
}
/// Returns the scalar or ordered-list address form without parsing it as an IP address.
#[must_use]
pub const fn addresses(&self) -> &BuildExtraHostAddresses {
&self.addresses
}
/// Returns the complete mapping-entry span.
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
}
/// Addresses authored for one build host mapping key.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BuildExtraHostAddresses {
/// One raw string address.
Scalar(Located<String>),
/// Ordered raw string addresses.
List {
/// The complete nested sequence span.
span: SourceSpan,
/// Raw addresses in authored order.
values: Vec<Located<String>>,
},
}
impl BuildExtraHostAddresses {
/// Returns the scalar address when that form was authored.
#[must_use]
pub const fn as_scalar(&self) -> Option<&Located<String>> {
match self {
Self::Scalar(value) => Some(value),
Self::List { .. } => None,
}
}
/// Returns ordered addresses when the nested list form was authored.
#[must_use]
pub fn as_list(&self) -> Option<&[Located<String>]> {
let Self::List { values, .. } = self else {
return None;
};
Some(values)
}
/// Returns the complete address-form span.
#[must_use]
pub const fn span(&self) -> SourceSpan {
match self {
Self::Scalar(value) => value.span(),
Self::List { span, .. } => *span,
}
}
}