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
//! Shared scalar and collection values used by the typed Compose model.
use super::Located;
use crate::source::SourceSpan;
/// A Compose boolean before optional interpolation is evaluated.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BooleanValue {
/// A YAML boolean literal.
Literal(bool),
/// A scalar expression whose result must later be validated as a boolean.
Expression(String),
}
/// A YAML scalar retained without applying Compose interpolation or coercion.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ComposeScalar {
/// An explicit YAML null.
Null,
/// A YAML boolean.
Boolean(bool),
/// A numeric scalar with its authored semantic spelling retained.
Number(String),
/// A string scalar, which may still contain interpolation expressions.
String(String),
}
/// One source-aware key/value entry from a Compose mapping.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct KeyValueEntry {
key: Located<String>,
value: Located<ComposeScalar>,
span: SourceSpan,
}
impl KeyValueEntry {
pub(crate) const fn new(key: Located<String>, value: Located<ComposeScalar>, span: SourceSpan) -> Self {
Self { key, value, span }
}
/// Returns the entry key.
#[must_use]
pub const fn key(&self) -> &Located<String> {
&self.key
}
/// Returns the scalar entry value.
#[must_use]
pub const fn value(&self) -> &Located<ComposeScalar> {
&self.value
}
/// Returns the complete key/value span.
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
}
/// A Compose labels value with its list or mapping form retained.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Labels {
/// List syntax such as `com.example.role=database`.
List {
/// The complete sequence span.
span: SourceSpan,
/// Label strings in authored order.
values: Vec<Located<String>>,
},
/// Mapping syntax with scalar values.
Map {
/// The complete mapping span.
span: SourceSpan,
/// Label entries in authored order.
entries: Vec<KeyValueEntry>,
},
}
impl Labels {
/// Returns the authored collection span.
#[must_use]
pub const fn span(&self) -> SourceSpan {
match self {
Self::List { span, .. } | Self::Map { span, .. } => *span,
}
}
}