1 + | // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
|
2 + |
|
3 + | /// Describes one specific validation failure for an input member.
|
4 + | #[derive(
|
5 + | ::std::clone::Clone, ::std::cmp::Eq, ::std::cmp::PartialEq, ::std::fmt::Debug, ::std::hash::Hash,
|
6 + | )]
|
7 + | pub struct ValidationExceptionField {
|
8 + | /// A JSONPointer expression to the structure member whose value failed to satisfy the modeled constraints.
|
9 + | pub path: ::std::string::String,
|
10 + | /// A detailed description of the validation failure.
|
11 + | pub message: ::std::string::String,
|
12 + | }
|
13 + | impl ValidationExceptionField {
|
14 + | /// A JSONPointer expression to the structure member whose value failed to satisfy the modeled constraints.
|
15 + | pub fn path(&self) -> &str {
|
16 + | use std::ops::Deref;
|
17 + | self.path.deref()
|
18 + | }
|
19 + | /// A detailed description of the validation failure.
|
20 + | pub fn message(&self) -> &str {
|
21 + | use std::ops::Deref;
|
22 + | self.message.deref()
|
23 + | }
|
24 + | }
|
25 + | impl ValidationExceptionField {
|
26 + | /// Creates a new builder-style object to manufacture [`ValidationExceptionField`](crate::model::ValidationExceptionField).
|
27 + | pub fn builder() -> crate::model::validation_exception_field::Builder {
|
28 + | crate::model::validation_exception_field::Builder::default()
|
29 + | }
|
30 + | }
|
31 + |
|
32 + | #[allow(missing_docs)] // documentation missing in model
|
33 + | ///
|
34 + | /// This is a constrained type because its corresponding modeled Smithy shape has one or more
|
35 + | /// [constraint traits]. Use [`ComplexSet::try_from`] to construct values of this type.
|
36 + | ///
|
37 + | /// [constraint traits]: https://smithy.io/2.0/spec/constraint-traits.html
|
38 + | ///
|
39 + | #[derive(
|
40 + | ::std::clone::Clone, ::std::cmp::Eq, ::std::cmp::PartialEq, ::std::fmt::Debug, ::std::hash::Hash,
|
41 + | )]
|
42 + | pub struct ComplexSet(pub(crate) ::std::vec::Vec<crate::model::ComplexSetStruct>);
|
43 + | impl ComplexSet {
|
44 + | /// Returns an immutable reference to the underlying [`::std::vec::Vec<crate::model::ComplexSetStruct>`].
|
45 + | pub fn inner(&self) -> &::std::vec::Vec<crate::model::ComplexSetStruct> {
|
46 + | &self.0
|
47 + | }
|
48 + | /// Consumes the value, returning the underlying [`::std::vec::Vec<crate::model::ComplexSetStruct>`].
|
49 + | pub fn into_inner(self) -> ::std::vec::Vec<crate::model::ComplexSetStruct> {
|
50 + | self.0
|
51 + | }
|
52 + |
|
53 + | fn check_unique_items(
|
54 + | items: ::std::vec::Vec<crate::model::ComplexSetStruct>,
|
55 + | ) -> ::std::result::Result<
|
56 + | ::std::vec::Vec<crate::model::ComplexSetStruct>,
|
57 + | crate::model::complex_set::ConstraintViolation,
|
58 + | > {
|
59 + | let mut seen = ::std::collections::HashMap::new();
|
60 + | let mut duplicate_indices = ::std::vec::Vec::new();
|
61 + | for (idx, item) in items.iter().enumerate() {
|
62 + | if let Some(prev_idx) = seen.insert(item, idx) {
|
63 + | duplicate_indices.push(prev_idx);
|
64 + | }
|
65 + | }
|
66 + |
|
67 + | let mut last_duplicate_indices = ::std::vec::Vec::new();
|
68 + | for idx in &duplicate_indices {
|
69 + | if let Some(prev_idx) = seen.remove(&items[*idx]) {
|
70 + | last_duplicate_indices.push(prev_idx);
|
71 + | }
|
72 + | }
|
73 + | duplicate_indices.extend(last_duplicate_indices);
|
74 + |
|
75 + | if !duplicate_indices.is_empty() {
|
76 + | debug_assert!(duplicate_indices.len() >= 2);
|
77 + | Err(
|
78 + | crate::model::complex_set::ConstraintViolation::UniqueItems {
|
79 + | duplicate_indices,
|
80 + | original: items,
|
81 + | },
|
82 + | )
|
83 + | } else {
|
84 + | Ok(items)
|
85 + | }
|
86 + | }
|
87 + | }
|
88 + | impl ::std::convert::TryFrom<::std::vec::Vec<crate::model::ComplexSetStruct>> for ComplexSet {
|
89 + | type Error = crate::model::complex_set::ConstraintViolation;
|
90 + |
|
91 + | /// Constructs a `ComplexSet` from an [`::std::vec::Vec<crate::model::ComplexSetStruct>`], failing when the provided value does not satisfy the modeled constraints.
|
92 + | fn try_from(
|
93 + | value: ::std::vec::Vec<crate::model::ComplexSetStruct>,
|
94 + | ) -> ::std::result::Result<Self, Self::Error> {
|
95 + | let value = Self::check_unique_items(value)?;
|
96 + |
|
97 + | Ok(Self(value))
|
98 + | }
|
99 + | }
|
100 + |
|
101 + | impl ::std::convert::From<ComplexSet> for ::std::vec::Vec<crate::model::ComplexSetStruct> {
|
102 + | fn from(value: ComplexSet) -> Self {
|
103 + | value.into_inner()
|
104 + | }
|
105 + | }
|
106 + | impl crate::constrained::Constrained for ComplexSet {
|
107 + | type Unconstrained = crate::unconstrained::complex_set_unconstrained::ComplexSetUnconstrained;
|
108 + | }
|
109 + |
|
110 + | #[allow(missing_docs)] // documentation missing in model
|
111 + | #[derive(
|
112 + | ::std::clone::Clone, ::std::cmp::Eq, ::std::cmp::PartialEq, ::std::fmt::Debug, ::std::hash::Hash,
|
113 + | )]
|
114 + | pub struct ComplexSetStruct {
|
115 + | #[allow(missing_docs)] // documentation missing in model
|
116 + | pub foo: ::std::option::Option<bool>,
|
117 + | #[allow(missing_docs)] // documentation missing in model
|
118 + | pub blob: ::std::option::Option<::aws_smithy_types::Blob>,
|
119 + | }
|
120 + | impl ComplexSetStruct {
|
121 + | #[allow(missing_docs)] // documentation missing in model
|
122 + | pub fn foo(&self) -> ::std::option::Option<bool> {
|
123 + | self.foo
|
124 + | }
|
125 + | #[allow(missing_docs)] // documentation missing in model
|
126 + | pub fn blob(&self) -> ::std::option::Option<&::aws_smithy_types::Blob> {
|
127 + | self.blob.as_ref()
|
128 + | }
|
129 + | }
|
130 + | impl ComplexSetStruct {
|
131 + | /// Creates a new builder-style object to manufacture [`ComplexSetStruct`](crate::model::ComplexSetStruct).
|
132 + | pub fn builder() -> crate::model::complex_set_struct::Builder {
|
133 + | crate::model::complex_set_struct::Builder::default()
|
134 + | }
|
135 + | }
|
136 + | impl crate::constrained::Constrained for crate::model::ComplexSetStruct {
|
137 + | type Unconstrained = crate::model::complex_set_struct::Builder;
|
138 + | }
|
139 + |
|
140 + | #[allow(missing_docs)] // documentation missing in model
|
141 + | ///
|
142 + | /// This is a constrained type because its corresponding modeled Smithy shape has one or more
|
143 + | /// [constraint traits]. Use [`SimpleSet::try_from`] to construct values of this type.
|
144 + | ///
|
145 + | /// [constraint traits]: https://smithy.io/2.0/spec/constraint-traits.html
|
146 + | ///
|
147 + | #[derive(
|
148 + | ::std::clone::Clone, ::std::cmp::Eq, ::std::cmp::PartialEq, ::std::fmt::Debug, ::std::hash::Hash,
|
149 + | )]
|
150 + | pub struct SimpleSet(pub(crate) ::std::vec::Vec<::std::string::String>);
|
151 + | impl SimpleSet {
|
152 + | /// Returns an immutable reference to the underlying [`::std::vec::Vec<::std::string::String>`].
|
153 + | pub fn inner(&self) -> &::std::vec::Vec<::std::string::String> {
|
154 + | &self.0
|
155 + | }
|
156 + | /// Consumes the value, returning the underlying [`::std::vec::Vec<::std::string::String>`].
|
157 + | pub fn into_inner(self) -> ::std::vec::Vec<::std::string::String> {
|
158 + | self.0
|
159 + | }
|
160 + |
|
161 + | fn check_unique_items(
|
162 + | items: ::std::vec::Vec<::std::string::String>,
|
163 + | ) -> ::std::result::Result<
|
164 + | ::std::vec::Vec<::std::string::String>,
|
165 + | crate::model::simple_set::ConstraintViolation,
|
166 + | > {
|
167 + | let mut seen = ::std::collections::HashMap::new();
|
168 + | let mut duplicate_indices = ::std::vec::Vec::new();
|
169 + | for (idx, item) in items.iter().enumerate() {
|
170 + | if let Some(prev_idx) = seen.insert(item, idx) {
|
171 + | duplicate_indices.push(prev_idx);
|
172 + | }
|
173 + | }
|
174 + |
|
175 + | let mut last_duplicate_indices = ::std::vec::Vec::new();
|
176 + | for idx in &duplicate_indices {
|
177 + | if let Some(prev_idx) = seen.remove(&items[*idx]) {
|
178 + | last_duplicate_indices.push(prev_idx);
|
179 + | }
|
180 + | }
|
181 + | duplicate_indices.extend(last_duplicate_indices);
|
182 + |
|
183 + | if !duplicate_indices.is_empty() {
|
184 + | debug_assert!(duplicate_indices.len() >= 2);
|
185 + | Err(crate::model::simple_set::ConstraintViolation::UniqueItems {
|
186 + | duplicate_indices,
|
187 + | original: items,
|
188 + | })
|
189 + | } else {
|
190 + | Ok(items)
|
191 + | }
|
192 + | }
|
193 + | }
|
194 + | impl ::std::convert::TryFrom<::std::vec::Vec<::std::string::String>> for SimpleSet {
|
195 + | type Error = crate::model::simple_set::ConstraintViolation;
|
196 + |
|
197 + | /// Constructs a `SimpleSet` from an [`::std::vec::Vec<::std::string::String>`], failing when the provided value does not satisfy the modeled constraints.
|
198 + | fn try_from(
|
199 + | value: ::std::vec::Vec<::std::string::String>,
|
200 + | ) -> ::std::result::Result<Self, Self::Error> {
|
201 + | let value = Self::check_unique_items(value)?;
|
202 + |
|
203 + | Ok(Self(value))
|
204 + | }
|
205 + | }
|
206 + |
|
207 + | impl ::std::convert::From<SimpleSet> for ::std::vec::Vec<::std::string::String> {
|
208 + | fn from(value: SimpleSet) -> Self {
|
209 + | value.into_inner()
|
210 + | }
|
211 + | }
|
212 + | impl crate::constrained::Constrained for SimpleSet {
|
213 + | type Unconstrained = crate::unconstrained::simple_set_unconstrained::SimpleSetUnconstrained;
|
214 + | }
|
215 + |
|
216 + | /// See [`ValidationExceptionField`](crate::model::ValidationExceptionField).
|
217 + | pub mod validation_exception_field {
|
218 + |
|
219 + | #[derive(::std::cmp::PartialEq, ::std::fmt::Debug)]
|
220 + | /// Holds one variant for each of the ways the builder can fail.
|
221 + | #[non_exhaustive]
|
222 + | #[allow(clippy::enum_variant_names)]
|
223 + | pub enum ConstraintViolation {
|
224 + | /// `path` was not provided but it is required when building `ValidationExceptionField`.
|
225 + | MissingPath,
|
226 + | /// `message` was not provided but it is required when building `ValidationExceptionField`.
|
227 + | MissingMessage,
|
228 + | }
|
229 + | impl ::std::fmt::Display for ConstraintViolation {
|
230 + | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
231 + | match self {
|
232 + | ConstraintViolation::MissingPath => write!(f, "`path` was not provided but it is required when building `ValidationExceptionField`"),
|
233 + | ConstraintViolation::MissingMessage => write!(f, "`message` was not provided but it is required when building `ValidationExceptionField`"),
|
234 + | }
|
235 + | }
|
236 + | }
|
237 + | impl ::std::error::Error for ConstraintViolation {}
|
238 + | impl ::std::convert::TryFrom<Builder> for crate::model::ValidationExceptionField {
|
239 + | type Error = ConstraintViolation;
|
240 + |
|
241 + | fn try_from(builder: Builder) -> ::std::result::Result<Self, Self::Error> {
|
242 + | builder.build()
|
243 + | }
|
244 + | }
|
245 + | /// A builder for [`ValidationExceptionField`](crate::model::ValidationExceptionField).
|
246 + | #[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug)]
|
247 + | pub struct Builder {
|
248 + | pub(crate) path: ::std::option::Option<::std::string::String>,
|
249 + | pub(crate) message: ::std::option::Option<::std::string::String>,
|
250 + | }
|
251 + | impl Builder {
|
252 + | /// A JSONPointer expression to the structure member whose value failed to satisfy the modeled constraints.
|
253 + | pub fn path(mut self, input: ::std::string::String) -> Self {
|
254 + | self.path = Some(input);
|
255 + | self
|
256 + | }
|
257 + | /// A detailed description of the validation failure.
|
258 + | pub fn message(mut self, input: ::std::string::String) -> Self {
|
259 + | self.message = Some(input);
|
260 + | self
|
261 + | }
|
262 + | /// Consumes the builder and constructs a [`ValidationExceptionField`](crate::model::ValidationExceptionField).
|
263 + | ///
|
264 + | /// The builder fails to construct a [`ValidationExceptionField`](crate::model::ValidationExceptionField) if a [`ConstraintViolation`] occurs.
|
265 + | ///
|
266 + | /// If the builder fails, it will return the _first_ encountered [`ConstraintViolation`].
|
267 + | pub fn build(self) -> Result<crate::model::ValidationExceptionField, ConstraintViolation> {
|
268 + | self.build_enforcing_all_constraints()
|
269 + | }
|
270 + | fn build_enforcing_all_constraints(
|
271 + | self,
|
272 + | ) -> Result<crate::model::ValidationExceptionField, ConstraintViolation> {
|
273 + | Ok(crate::model::ValidationExceptionField {
|
274 + | path: self.path.ok_or(ConstraintViolation::MissingPath)?,
|
275 + | message: self.message.ok_or(ConstraintViolation::MissingMessage)?,
|
276 + | })
|
277 + | }
|
278 + | }
|
279 + | }
|
280 + | /// See [`ComplexSet`](crate::model::ComplexSet).
|
281 + | pub mod complex_set {
|
282 + |
|
283 + | #[allow(clippy::enum_variant_names)]
|
284 + | #[derive(Debug, PartialEq)]
|
285 + | pub enum ConstraintViolation {
|
286 + | /// Constraint violation error when the list does not contain unique items
|
287 + | UniqueItems {
|
288 + | /// A vector of indices into `original` pointing to all duplicate items. This vector has
|
289 + | /// at least two elements.
|
290 + | /// More specifically, for every element `idx_1` in `duplicate_indices`, there exists another
|
291 + | /// distinct element `idx_2` such that `original[idx_1] == original[idx_2]` is `true`.
|
292 + | /// Nothing is guaranteed about the order of the indices.
|
293 + | duplicate_indices: ::std::vec::Vec<usize>,
|
294 + | /// The original vector, that contains duplicate items.
|
295 + | original: ::std::vec::Vec<crate::model::ComplexSetStruct>,
|
296 + | },
|
297 + | }
|
298 + |
|
299 + | impl ::std::fmt::Display for ConstraintViolation {
|
300 + | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
301 + | let message = match self {
|
302 + | Self::UniqueItems { duplicate_indices, .. } =>
|
303 + | format!("Value with repeated values at indices {:?} provided for 'com.amazonaws.constraints#ComplexSet' failed to satisfy constraint: Member must have unique values", &duplicate_indices),
|
304 + | };
|
305 + | write!(f, "{message}")
|
306 + | }
|
307 + | }
|
308 + |
|
309 + | impl ::std::error::Error for ConstraintViolation {}
|
310 + | impl ConstraintViolation {
|
311 + | pub(crate) fn as_validation_exception_field(
|
312 + | self,
|
313 + | path: ::std::string::String,
|
314 + | ) -> crate::model::ValidationExceptionField {
|
315 + | match self {
|
316 + | Self::UniqueItems { duplicate_indices, .. } =>
|
317 + | crate::model::ValidationExceptionField {
|
318 + | message: format!("Value with repeated values at indices {:?} at '{}' failed to satisfy constraint: Member must have unique values", &duplicate_indices, &path),
|
319 + | path,
|
320 + | },
|
321 + | }
|
322 + | }
|
323 + | }
|
324 + | }
|
325 + | /// See [`ComplexSetStruct`](crate::model::ComplexSetStruct).
|
326 + | pub mod complex_set_struct {
|
327 + |
|
328 + | impl ::std::convert::From<Builder> for crate::model::ComplexSetStruct {
|
329 + | fn from(builder: Builder) -> Self {
|
330 + | builder.build()
|
331 + | }
|
332 + | }
|
333 + | /// A builder for [`ComplexSetStruct`](crate::model::ComplexSetStruct).
|
334 + | #[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug)]
|
335 + | pub struct Builder {
|
336 + | pub(crate) foo: ::std::option::Option<bool>,
|
337 + | pub(crate) blob: ::std::option::Option<::aws_smithy_types::Blob>,
|
338 + | }
|
339 + | impl Builder {
|
340 + | #[allow(missing_docs)] // documentation missing in model
|
341 + | pub fn foo(mut self, input: ::std::option::Option<bool>) -> Self {
|
342 + | self.foo = input;
|
343 + | self
|
344 + | }
|
345 + | #[allow(missing_docs)] // documentation missing in model
|
346 + | pub(crate) fn set_foo(mut self, input: Option<impl ::std::convert::Into<bool>>) -> Self {
|
347 + | self.foo = input.map(|v| v.into());
|
348 + | self
|
349 + | }
|
350 + | #[allow(missing_docs)] // documentation missing in model
|
351 + | pub fn blob(mut self, input: ::std::option::Option<::aws_smithy_types::Blob>) -> Self {
|
352 + | self.blob = input;
|
353 + | self
|
354 + | }
|
355 + | #[allow(missing_docs)] // documentation missing in model
|
356 + | pub(crate) fn set_blob(
|
357 + | mut self,
|
358 + | input: Option<impl ::std::convert::Into<::aws_smithy_types::Blob>>,
|
359 + | ) -> Self {
|
360 + | self.blob = input.map(|v| v.into());
|
361 + | self
|
362 + | }
|
363 + | /// Consumes the builder and constructs a [`ComplexSetStruct`](crate::model::ComplexSetStruct).
|
364 + | pub fn build(self) -> crate::model::ComplexSetStruct {
|
365 + | self.build_enforcing_all_constraints()
|
366 + | }
|
367 + | fn build_enforcing_all_constraints(self) -> crate::model::ComplexSetStruct {
|
368 + | crate::model::ComplexSetStruct {
|
369 + | foo: self.foo,
|
370 + | blob: self.blob,
|
371 + | }
|
372 + | }
|
373 + | }
|
374 + | }
|
375 + | /// See [`SimpleSet`](crate::model::SimpleSet).
|
376 + | pub mod simple_set {
|
377 + |
|
378 + | #[allow(clippy::enum_variant_names)]
|
379 + | #[derive(Debug, PartialEq)]
|
380 + | pub enum ConstraintViolation {
|
381 + | /// Constraint violation error when the list does not contain unique items
|
382 + | UniqueItems {
|
383 + | /// A vector of indices into `original` pointing to all duplicate items. This vector has
|
384 + | /// at least two elements.
|
385 + | /// More specifically, for every element `idx_1` in `duplicate_indices`, there exists another
|
386 + | /// distinct element `idx_2` such that `original[idx_1] == original[idx_2]` is `true`.
|
387 + | /// Nothing is guaranteed about the order of the indices.
|
388 + | duplicate_indices: ::std::vec::Vec<usize>,
|
389 + | /// The original vector, that contains duplicate items.
|
390 + | original: ::std::vec::Vec<::std::string::String>,
|
391 + | },
|
392 + | }
|
393 + |
|
394 + | impl ::std::fmt::Display for ConstraintViolation {
|
395 + | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
396 + | let message = match self {
|
397 + | Self::UniqueItems { duplicate_indices, .. } =>
|
398 + | format!("Value with repeated values at indices {:?} provided for 'com.amazonaws.constraints#SimpleSet' failed to satisfy constraint: Member must have unique values", &duplicate_indices),
|
399 + | };
|
400 + | write!(f, "{message}")
|
401 + | }
|
402 + | }
|
403 + |
|
404 + | impl ::std::error::Error for ConstraintViolation {}
|
405 + | impl ConstraintViolation {
|
406 + | pub(crate) fn as_validation_exception_field(
|
407 + | self,
|
408 + | path: ::std::string::String,
|
409 + | ) -> crate::model::ValidationExceptionField {
|
410 + | match self {
|
411 + | Self::UniqueItems { duplicate_indices, .. } =>
|
412 + | crate::model::ValidationExceptionField {
|
413 + | message: format!("Value with repeated values at indices {:?} at '{}' failed to satisfy constraint: Member must have unique values", &duplicate_indices, &path),
|
414 + | path,
|
415 + | },
|
416 + | }
|
417 + | }
|
418 + | }
|
419 + | }
|