1 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.
|
2 + | #[allow(missing_docs)] // documentation missing in model
|
3 + | ///
|
4 + | /// This is a constrained type because its corresponding modeled Smithy shape has one or more
|
5 + | /// [constraint traits]. Use [`SimpleSet::try_from`] to construct values of this type.
|
6 + | ///
|
7 + | /// [constraint traits]: https://smithy.io/2.0/spec/constraint-traits.html
|
8 + | ///
|
4 9 | #[derive(
|
5 10 | ::std::clone::Clone, ::std::cmp::Eq, ::std::cmp::PartialEq, ::std::fmt::Debug, ::std::hash::Hash,
|
6 11 | )]
|
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()
|
12 + | pub struct SimpleSet(pub(crate) ::std::vec::Vec<::std::string::String>);
|
13 + | impl SimpleSet {
|
14 + | /// Returns an immutable reference to the underlying [`::std::vec::Vec<::std::string::String>`].
|
15 + | pub fn inner(&self) -> &::std::vec::Vec<::std::string::String> {
|
16 + | &self.0
|
18 17 | }
|
19 - | /// A detailed description of the validation failure.
|
20 - | pub fn message(&self) -> &str {
|
21 - | use std::ops::Deref;
|
22 - | self.message.deref()
|
18 + | /// Consumes the value, returning the underlying [`::std::vec::Vec<::std::string::String>`].
|
19 + | pub fn into_inner(self) -> ::std::vec::Vec<::std::string::String> {
|
20 + | self.0
|
21 + | }
|
22 + |
|
23 + | fn check_unique_items(
|
24 + | items: ::std::vec::Vec<::std::string::String>,
|
25 + | ) -> ::std::result::Result<
|
26 + | ::std::vec::Vec<::std::string::String>,
|
27 + | crate::model::simple_set::ConstraintViolation,
|
28 + | > {
|
29 + | let mut seen = ::std::collections::HashMap::new();
|
30 + | let mut duplicate_indices = ::std::vec::Vec::new();
|
31 + | for (idx, item) in items.iter().enumerate() {
|
32 + | if let Some(prev_idx) = seen.insert(item, idx) {
|
33 + | duplicate_indices.push(prev_idx);
|
34 + | }
|
35 + | }
|
36 + |
|
37 + | let mut last_duplicate_indices = ::std::vec::Vec::new();
|
38 + | for idx in &duplicate_indices {
|
39 + | if let Some(prev_idx) = seen.remove(&items[*idx]) {
|
40 + | last_duplicate_indices.push(prev_idx);
|
41 + | }
|
42 + | }
|
43 + | duplicate_indices.extend(last_duplicate_indices);
|
44 + |
|
45 + | if !duplicate_indices.is_empty() {
|
46 + | debug_assert!(duplicate_indices.len() >= 2);
|
47 + | Err(crate::model::simple_set::ConstraintViolation::UniqueItems {
|
48 + | duplicate_indices,
|
49 + | original: items,
|
50 + | })
|
51 + | } else {
|
52 + | Ok(items)
|
53 + | }
|
23 54 | }
|
24 55 | }
|
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()
|
56 + | impl ::std::convert::TryFrom<::std::vec::Vec<::std::string::String>> for SimpleSet {
|
57 + | type Error = crate::model::simple_set::ConstraintViolation;
|
58 + |
|
59 + | /// Constructs a `SimpleSet` from an [`::std::vec::Vec<::std::string::String>`], failing when the provided value does not satisfy the modeled constraints.
|
60 + | fn try_from(
|
61 + | value: ::std::vec::Vec<::std::string::String>,
|
62 + | ) -> ::std::result::Result<Self, Self::Error> {
|
63 + | let value = Self::check_unique_items(value)?;
|
64 + |
|
65 + | Ok(Self(value))
|
29 66 | }
|
30 67 | }
|
31 68 |
|
69 + | impl ::std::convert::From<SimpleSet> for ::std::vec::Vec<::std::string::String> {
|
70 + | fn from(value: SimpleSet) -> Self {
|
71 + | value.into_inner()
|
72 + | }
|
73 + | }
|
74 + | impl crate::constrained::Constrained for SimpleSet {
|
75 + | type Unconstrained = crate::unconstrained::simple_set_unconstrained::SimpleSetUnconstrained;
|
76 + | }
|
77 + |
|
32 78 | #[allow(missing_docs)] // documentation missing in model
|
33 79 | ///
|
34 80 | /// This is a constrained type because its corresponding modeled Smithy shape has one or more
|
35 81 | /// [constraint traits]. Use [`ComplexSet::try_from`] to construct values of this type.
|
36 82 | ///
|
37 83 | /// [constraint traits]: https://smithy.io/2.0/spec/constraint-traits.html
|
38 84 | ///
|
39 85 | #[derive(
|
40 86 | ::std::clone::Clone, ::std::cmp::Eq, ::std::cmp::PartialEq, ::std::fmt::Debug, ::std::hash::Hash,
|
41 87 | )]
|
130 176 | impl ComplexSetStruct {
|
131 177 | /// Creates a new builder-style object to manufacture [`ComplexSetStruct`](crate::model::ComplexSetStruct).
|
132 178 | pub fn builder() -> crate::model::complex_set_struct::Builder {
|
133 179 | crate::model::complex_set_struct::Builder::default()
|
134 180 | }
|
135 181 | }
|
136 182 | impl crate::constrained::Constrained for crate::model::ComplexSetStruct {
|
137 183 | type Unconstrained = crate::model::complex_set_struct::Builder;
|
138 184 | }
|
139 185 |
|
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 - | ///
|
186 + | /// Describes one specific validation failure for an input member.
|
147 187 | #[derive(
|
148 188 | ::std::clone::Clone, ::std::cmp::Eq, ::std::cmp::PartialEq, ::std::fmt::Debug, ::std::hash::Hash,
|
149 189 | )]
|
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 - | }
|
190 + | pub struct ValidationExceptionField {
|
191 + | /// A JSONPointer expression to the structure member whose value failed to satisfy the modeled constraints.
|
192 + | pub path: ::std::string::String,
|
193 + | /// A detailed description of the validation failure.
|
194 + | pub message: ::std::string::String,
|
193 195 | }
|
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))
|
196 + | impl ValidationExceptionField {
|
197 + | /// A JSONPointer expression to the structure member whose value failed to satisfy the modeled constraints.
|
198 + | pub fn path(&self) -> &str {
|
199 + | use std::ops::Deref;
|
200 + | self.path.deref()
|
204 201 | }
|
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()
|
202 + | /// A detailed description of the validation failure.
|
203 + | pub fn message(&self) -> &str {
|
204 + | use std::ops::Deref;
|
205 + | self.message.deref()
|
210 206 | }
|
211 207 | }
|
212 - | impl crate::constrained::Constrained for SimpleSet {
|
213 - | type Unconstrained = crate::unconstrained::simple_set_unconstrained::SimpleSetUnconstrained;
|
208 + | impl ValidationExceptionField {
|
209 + | /// Creates a new builder-style object to manufacture [`ValidationExceptionField`](crate::model::ValidationExceptionField).
|
210 + | pub fn builder() -> crate::model::validation_exception_field::Builder {
|
211 + | crate::model::validation_exception_field::Builder::default()
|
212 + | }
|
214 213 | }
|
214 + | /// See [`SimpleSet`](crate::model::SimpleSet).
|
215 + | pub mod simple_set {
|
215 216 |
|
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 217 | #[allow(clippy::enum_variant_names)]
|
218 + | #[derive(Debug, PartialEq)]
|
223 219 | 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,
|
220 + | /// Constraint violation error when the list does not contain unique items
|
221 + | UniqueItems {
|
222 + | /// A vector of indices into `original` pointing to all duplicate items. This vector has
|
223 + | /// at least two elements.
|
224 + | /// More specifically, for every element `idx_1` in `duplicate_indices`, there exists another
|
225 + | /// distinct element `idx_2` such that `original[idx_1] == original[idx_2]` is `true`.
|
226 + | /// Nothing is guaranteed about the order of the indices.
|
227 + | duplicate_indices: ::std::vec::Vec<usize>,
|
228 + | /// The original vector, that contains duplicate items.
|
229 + | original: ::std::vec::Vec<::std::string::String>,
|
230 + | },
|
228 231 | }
|
232 + |
|
229 233 | impl ::std::fmt::Display for ConstraintViolation {
|
230 234 | 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 + | let message = match self {
|
236 + | Self::UniqueItems { duplicate_indices, .. } =>
|
237 + | format!("Value with repeated values at indices {:?} provided for 'com.amazonaws.constraints#SimpleSet' failed to satisfy constraint: Member must have unique values", &duplicate_indices),
|
238 + | };
|
239 + | write!(f, "{message}")
|
235 240 | }
|
236 241 | }
|
237 - | impl ::std::error::Error for ConstraintViolation {}
|
238 - | impl ::std::convert::TryFrom<Builder> for crate::model::ValidationExceptionField {
|
239 - | type Error = ConstraintViolation;
|
240 242 |
|
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(
|
243 + | impl ::std::error::Error for ConstraintViolation {}
|
244 + | impl ConstraintViolation {
|
245 + | pub(crate) fn as_validation_exception_field(
|
271 246 | 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 - | })
|
247 + | path: ::std::string::String,
|
248 + | ) -> crate::model::ValidationExceptionField {
|
249 + | match self {
|
250 + | Self::UniqueItems { duplicate_indices, .. } =>
|
251 + | crate::model::ValidationExceptionField {
|
252 + | message: format!("Value with repeated values at indices {:?} at '{}' failed to satisfy constraint: Member must have unique values", &duplicate_indices, &path),
|
253 + | path,
|
254 + | },
|
255 + | }
|
277 256 | }
|
278 257 | }
|
279 258 | }
|
280 259 | /// See [`ComplexSet`](crate::model::ComplexSet).
|
281 260 | pub mod complex_set {
|
282 261 |
|
283 262 | #[allow(clippy::enum_variant_names)]
|
284 263 | #[derive(Debug, PartialEq)]
|
285 264 | pub enum ConstraintViolation {
|
286 265 | /// Constraint violation error when the list does not contain unique items
|
365 344 | self.build_enforcing_all_constraints()
|
366 345 | }
|
367 346 | fn build_enforcing_all_constraints(self) -> crate::model::ComplexSetStruct {
|
368 347 | crate::model::ComplexSetStruct {
|
369 348 | foo: self.foo,
|
370 349 | blob: self.blob,
|
371 350 | }
|
372 351 | }
|
373 352 | }
|
374 353 | }
|
375 - | /// See [`SimpleSet`](crate::model::SimpleSet).
|
376 - | pub mod simple_set {
|
354 + | /// See [`ValidationExceptionField`](crate::model::ValidationExceptionField).
|
355 + | pub mod validation_exception_field {
|
377 356 |
|
357 + | #[derive(::std::cmp::PartialEq, ::std::fmt::Debug)]
|
358 + | /// Holds one variant for each of the ways the builder can fail.
|
359 + | #[non_exhaustive]
|
378 360 | #[allow(clippy::enum_variant_names)]
|
379 - | #[derive(Debug, PartialEq)]
|
380 361 | 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 - | },
|
362 + | /// `path` was not provided but it is required when building `ValidationExceptionField`.
|
363 + | MissingPath,
|
364 + | /// `message` was not provided but it is required when building `ValidationExceptionField`.
|
365 + | MissingMessage,
|
392 366 | }
|
393 - |
|
394 367 | impl ::std::fmt::Display for ConstraintViolation {
|
395 368 | 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}")
|
369 + | match self {
|
370 + | ConstraintViolation::MissingPath => write!(f, "`path` was not provided but it is required when building `ValidationExceptionField`"),
|
371 + | ConstraintViolation::MissingMessage => write!(f, "`message` was not provided but it is required when building `ValidationExceptionField`"),
|
372 + | }
|
401 373 | }
|
402 374 | }
|
403 - |
|
404 375 | impl ::std::error::Error for ConstraintViolation {}
|
405 - | impl ConstraintViolation {
|
406 - | pub(crate) fn as_validation_exception_field(
|
376 + | impl ::std::convert::TryFrom<Builder> for crate::model::ValidationExceptionField {
|
377 + | type Error = ConstraintViolation;
|
378 + |
|
379 + | fn try_from(builder: Builder) -> ::std::result::Result<Self, Self::Error> {
|
380 + | builder.build()
|
381 + | }
|
382 + | }
|
383 + | /// A builder for [`ValidationExceptionField`](crate::model::ValidationExceptionField).
|
384 + | #[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug)]
|
385 + | pub struct Builder {
|
386 + | pub(crate) path: ::std::option::Option<::std::string::String>,
|
387 + | pub(crate) message: ::std::option::Option<::std::string::String>,
|
388 + | }
|
389 + | impl Builder {
|
390 + | /// A JSONPointer expression to the structure member whose value failed to satisfy the modeled constraints.
|
391 + | pub fn path(mut self, input: ::std::string::String) -> Self {
|
392 + | self.path = Some(input);
|
393 + | self
|
394 + | }
|
395 + | /// A detailed description of the validation failure.
|
396 + | pub fn message(mut self, input: ::std::string::String) -> Self {
|
397 + | self.message = Some(input);
|
398 + | self
|
399 + | }
|
400 + | /// Consumes the builder and constructs a [`ValidationExceptionField`](crate::model::ValidationExceptionField).
|
401 + | ///
|
402 + | /// The builder fails to construct a [`ValidationExceptionField`](crate::model::ValidationExceptionField) if a [`ConstraintViolation`] occurs.
|
403 + | ///
|
404 + | /// If the builder fails, it will return the _first_ encountered [`ConstraintViolation`].
|
405 + | pub fn build(self) -> Result<crate::model::ValidationExceptionField, ConstraintViolation> {
|
406 + | self.build_enforcing_all_constraints()
|
407 + | }
|
408 + | fn build_enforcing_all_constraints(
|
407 409 | 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 - | }
|
410 + | ) -> Result<crate::model::ValidationExceptionField, ConstraintViolation> {
|
411 + | Ok(crate::model::ValidationExceptionField {
|
412 + | path: self.path.ok_or(ConstraintViolation::MissingPath)?,
|
413 + | message: self.message.ok_or(ConstraintViolation::MissingMessage)?,
|
414 + | })
|
417 415 | }
|
418 416 | }
|
419 417 | }
|