compose_lens/model/
build_extra_host.rs1use super::Located;
4use crate::source::SourceSpan;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
9pub enum BuildExtraHosts {
10 List {
12 span: SourceSpan,
14 values: Vec<Located<String>>,
16 },
17 Map {
19 span: SourceSpan,
21 entries: Vec<BuildExtraHostEntry>,
23 },
24}
25
26impl BuildExtraHosts {
27 #[must_use]
29 pub const fn span(&self) -> SourceSpan {
30 match self {
31 Self::List { span, .. } | Self::Map { span, .. } => *span,
32 }
33 }
34}
35
36#[derive(Debug, Clone, PartialEq, Eq)]
38pub struct BuildExtraHostEntry {
39 hostname: Located<String>,
40 addresses: BuildExtraHostAddresses,
41 span: SourceSpan,
42}
43
44impl BuildExtraHostEntry {
45 pub(crate) const fn new(hostname: Located<String>, addresses: BuildExtraHostAddresses, span: SourceSpan) -> Self {
46 Self {
47 hostname,
48 addresses,
49 span,
50 }
51 }
52
53 #[must_use]
55 pub const fn hostname(&self) -> &Located<String> {
56 &self.hostname
57 }
58
59 #[must_use]
61 pub const fn addresses(&self) -> &BuildExtraHostAddresses {
62 &self.addresses
63 }
64
65 #[must_use]
67 pub const fn span(&self) -> SourceSpan {
68 self.span
69 }
70}
71
72#[derive(Debug, Clone, PartialEq, Eq)]
74pub enum BuildExtraHostAddresses {
75 Scalar(Located<String>),
77 List {
79 span: SourceSpan,
81 values: Vec<Located<String>>,
83 },
84}
85
86impl BuildExtraHostAddresses {
87 #[must_use]
89 pub const fn as_scalar(&self) -> Option<&Located<String>> {
90 match self {
91 Self::Scalar(value) => Some(value),
92 Self::List { .. } => None,
93 }
94 }
95
96 #[must_use]
98 pub fn as_list(&self) -> Option<&[Located<String>]> {
99 let Self::List { values, .. } = self else {
100 return None;
101 };
102 Some(values)
103 }
104
105 #[must_use]
107 pub const fn span(&self) -> SourceSpan {
108 match self {
109 Self::Scalar(value) => value.span(),
110 Self::List { span, .. } => *span,
111 }
112 }
113}