compose_lens/model/
provider.rs1use crate::source::SourceSpan;
4
5use super::{ComposeScalar, FieldReference, Located};
6
7#[derive(Debug, Clone, PartialEq, Eq)]
9#[non_exhaustive]
10pub enum ProviderOptionValue {
11 Scalar(Located<ComposeScalar>),
13 Sequence {
15 span: SourceSpan,
17 items: Vec<ProviderOptionItem>,
19 },
20}
21
22impl ProviderOptionValue {
23 #[must_use]
25 pub const fn span(&self) -> SourceSpan {
26 match self {
27 Self::Scalar(value) => value.span(),
28 Self::Sequence { span, .. } => *span,
29 }
30 }
31}
32
33#[derive(Debug, Clone, PartialEq, Eq)]
35#[non_exhaustive]
36pub enum ProviderOptionItem {
37 Scalar(Located<ComposeScalar>),
39 Unmodeled {
41 span: SourceSpan,
43 },
44}
45
46impl ProviderOptionItem {
47 #[must_use]
49 pub const fn span(&self) -> SourceSpan {
50 match self {
51 Self::Scalar(value) => value.span(),
52 Self::Unmodeled { span } => *span,
53 }
54 }
55}
56
57#[derive(Debug, Clone, PartialEq, Eq)]
59pub struct ProviderOption {
60 name: Located<String>,
61 value: ProviderOptionValue,
62 span: SourceSpan,
63}
64
65impl ProviderOption {
66 pub(crate) const fn new(name: Located<String>, value: ProviderOptionValue, span: SourceSpan) -> Self {
67 Self { name, value, span }
68 }
69
70 #[must_use]
72 pub const fn name(&self) -> &Located<String> {
73 &self.name
74 }
75
76 #[must_use]
78 pub const fn value(&self) -> &ProviderOptionValue {
79 &self.value
80 }
81
82 #[must_use]
84 pub const fn span(&self) -> SourceSpan {
85 self.span
86 }
87}
88
89#[derive(Debug, Clone, PartialEq, Eq)]
91pub struct ProviderOptions {
92 span: SourceSpan,
93 entries: Vec<ProviderOption>,
94 unmodeled_entries: Vec<FieldReference>,
95}
96
97impl ProviderOptions {
98 pub(crate) const fn new(
99 span: SourceSpan,
100 entries: Vec<ProviderOption>,
101 unmodeled_entries: Vec<FieldReference>,
102 ) -> Self {
103 Self {
104 span,
105 entries,
106 unmodeled_entries,
107 }
108 }
109
110 #[must_use]
112 pub const fn span(&self) -> SourceSpan {
113 self.span
114 }
115
116 #[must_use]
118 pub fn entries(&self) -> &[ProviderOption] {
119 &self.entries
120 }
121
122 #[must_use]
124 pub fn unmodeled_entries(&self) -> &[FieldReference] {
125 &self.unmodeled_entries
126 }
127}
128
129#[derive(Debug, Clone, PartialEq, Eq)]
131pub struct Provider {
132 span: SourceSpan,
133 type_: Option<Located<String>>,
134 options: Option<ProviderOptions>,
135 extension_fields: Vec<FieldReference>,
136 unknown_fields: Vec<FieldReference>,
137}
138
139impl Provider {
140 pub(crate) const fn new(span: SourceSpan) -> Self {
141 Self {
142 span,
143 type_: None,
144 options: None,
145 extension_fields: Vec::new(),
146 unknown_fields: Vec::new(),
147 }
148 }
149
150 pub(crate) fn set_type(&mut self, value: Located<String>) {
151 self.type_ = Some(value);
152 }
153
154 pub(crate) fn set_options(&mut self, value: ProviderOptions) {
155 self.options = Some(value);
156 }
157
158 pub(crate) fn push_extension(&mut self, field: FieldReference) {
159 self.extension_fields.push(field);
160 }
161
162 pub(crate) fn push_unknown(&mut self, field: FieldReference) {
163 self.unknown_fields.push(field);
164 }
165
166 #[must_use]
168 pub const fn span(&self) -> SourceSpan {
169 self.span
170 }
171
172 #[must_use]
174 pub const fn type_(&self) -> Option<&Located<String>> {
175 self.type_.as_ref()
176 }
177
178 #[must_use]
180 pub const fn options(&self) -> Option<&ProviderOptions> {
181 self.options.as_ref()
182 }
183
184 #[must_use]
186 pub fn extension_fields(&self) -> &[FieldReference] {
187 &self.extension_fields
188 }
189
190 #[must_use]
192 pub fn unknown_fields(&self) -> &[FieldReference] {
193 &self.unknown_fields
194 }
195}