1 + | // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
|
2 + | pub(crate) fn de_constrained_union<'a, I>(
|
3 + | tokens: &mut ::std::iter::Peekable<I>,
|
4 + | ) -> ::std::result::Result<
|
5 + | Option<crate::unconstrained::constrained_union_unconstrained::ConstrainedUnionUnconstrained>,
|
6 + | ::aws_smithy_json::deserialize::error::DeserializeError,
|
7 + | >
|
8 + | where
|
9 + | I: Iterator<
|
10 + | Item = Result<
|
11 + | ::aws_smithy_json::deserialize::Token<'a>,
|
12 + | ::aws_smithy_json::deserialize::error::DeserializeError,
|
13 + | >,
|
14 + | >,
|
15 + | {
|
16 + | let mut variant = None;
|
17 + | match tokens.next().transpose()? {
|
18 + | Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => return Ok(None),
|
19 + | Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => loop {
|
20 + | match tokens.next().transpose()? {
|
21 + | Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
|
22 + | Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
|
23 + | if let ::std::option::Option::Some(::std::result::Result::Ok(
|
24 + | ::aws_smithy_json::deserialize::Token::ValueNull { .. },
|
25 + | )) = tokens.peek()
|
26 + | {
|
27 + | let _ = tokens.next().expect("peek returned a token")?;
|
28 + | continue;
|
29 + | }
|
30 + | let key = key.to_unescaped()?;
|
31 + | if key == "__type" {
|
32 + | ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
|
33 + | continue;
|
34 + | }
|
35 + | if variant.is_some() {
|
36 + | return Err(
|
37 + | ::aws_smithy_json::deserialize::error::DeserializeError::custom(
|
38 + | "encountered mixed variants in union",
|
39 + | ),
|
40 + | );
|
41 + | }
|
42 + | variant = match key.as_ref() {
|
43 + | "enumString" => {
|
44 + | Some(crate::unconstrained::constrained_union_unconstrained::ConstrainedUnionUnconstrained::EnumString(
|
45 + | ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?.map(|s|
|
46 + | s.to_unescaped().map(|u|
|
47 + | u.into_owned()
|
48 + | )
|
49 + | ).transpose()?
|
50 + | .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'enumString' cannot be null"))?
|
51 + | ))
|
52 + | }
|
53 + | "lengthString" => {
|
54 + | Some(crate::unconstrained::constrained_union_unconstrained::ConstrainedUnionUnconstrained::LengthString(
|
55 + | ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?.map(|s|
|
56 + | s.to_unescaped().map(|u|
|
57 + | u.into_owned()
|
58 + | )
|
59 + | ).transpose()?
|
60 + | .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'lengthString' cannot be null"))?
|
61 + | ))
|
62 + | }
|
63 + | "constrainedStructure" => {
|
64 + | Some(crate::unconstrained::constrained_union_unconstrained::ConstrainedUnionUnconstrained::ConstrainedStructure(
|
65 + | crate::protocol_serde::shape_con_b::de_con_b(tokens)?
|
66 + | .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'constrainedStructure' cannot be null"))?
|
67 + | ))
|
68 + | }
|
69 + | "conBList" => {
|
70 + | Some(crate::unconstrained::constrained_union_unconstrained::ConstrainedUnionUnconstrained::ConBList(
|
71 + | crate::protocol_serde::shape_con_b_list::de_con_b_list(tokens)?
|
72 + | .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'conBList' cannot be null"))?
|
73 + | ))
|
74 + | }
|
75 + | "conBSet" => {
|
76 + | Some(crate::unconstrained::constrained_union_unconstrained::ConstrainedUnionUnconstrained::ConBSet(
|
77 + | crate::protocol_serde::shape_con_b_set::de_con_b_set(tokens)?
|
78 + | .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'conBSet' cannot be null"))?
|
79 + | ))
|
80 + | }
|
81 + | "conBMap" => {
|
82 + | Some(crate::unconstrained::constrained_union_unconstrained::ConstrainedUnionUnconstrained::ConBMap(
|
83 + | crate::protocol_serde::shape_con_b_map::de_con_b_map(tokens)?
|
84 + | .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'conBMap' cannot be null"))?
|
85 + | ))
|
86 + | }
|
87 + | variant => return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!("unexpected union variant: {variant}")))
|
88 + | };
|
89 + | }
|
90 + | other => {
|
91 + | return Err(
|
92 + | ::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
|
93 + | "expected object key or end object, found: {other:?}"
|
94 + | )),
|
95 + | )
|
96 + | }
|
97 + | }
|
98 + | },
|
99 + | _ => {
|
100 + | return Err(
|
101 + | ::aws_smithy_json::deserialize::error::DeserializeError::custom(
|
102 + | "expected start object or null",
|
103 + | ),
|
104 + | )
|
105 + | }
|
106 + | }
|
107 + | if variant.is_none() {
|
108 + | return Err(
|
109 + | ::aws_smithy_json::deserialize::error::DeserializeError::custom(
|
110 + | "Union did not contain a valid variant.",
|
111 + | ),
|
112 + | );
|
113 + | }
|
114 + | Ok(variant)
|
115 + | }
|
116 + |
|
117 + | pub fn ser_constrained_union(
|
118 + | object_71: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
|
119 + | input: &crate::model::ConstrainedUnion,
|
120 + | ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
|
121 + | match input {
|
122 + | crate::model::ConstrainedUnion::EnumString(inner) => {
|
123 + | object_71.key("enumString").string(inner.as_str());
|
124 + | }
|
125 + | crate::model::ConstrainedUnion::LengthString(inner) => {
|
126 + | object_71.key("lengthString").string(inner.as_str());
|
127 + | }
|
128 + | crate::model::ConstrainedUnion::ConstrainedStructure(inner) => {
|
129 + | #[allow(unused_mut)]
|
130 + | let mut object_1 = object_71.key("constrainedStructure").start_object();
|
131 + | crate::protocol_serde::shape_con_b::ser_con_b(&mut object_1, inner)?;
|
132 + | object_1.finish();
|
133 + | }
|
134 + | crate::model::ConstrainedUnion::ConBList(inner) => {
|
135 + | let mut array_2 = object_71.key("conBList").start_array();
|
136 + | for item_3 in inner {
|
137 + | {
|
138 + | let mut array_4 = array_2.value().start_array();
|
139 + | for item_5 in item_3 {
|
140 + | {
|
141 + | #[allow(unused_mut)]
|
142 + | let mut object_6 = array_4.value().start_object();
|
143 + | crate::protocol_serde::shape_con_b::ser_con_b(&mut object_6, item_5)?;
|
144 + | object_6.finish();
|
145 + | }
|
146 + | }
|
147 + | array_4.finish();
|
148 + | }
|
149 + | }
|
150 + | array_2.finish();
|
151 + | }
|
152 + | crate::model::ConstrainedUnion::ConBSet(inner) => {
|
153 + | let mut array_7 = object_71.key("conBSet").start_array();
|
154 + | for item_8 in &inner.0 {
|
155 + | {
|
156 + | let mut array_9 = array_7.value().start_array();
|
157 + | for item_10 in &item_8.0 {
|
158 + | {
|
159 + | array_9.value().string(item_10.as_str());
|
160 + | }
|
161 + | }
|
162 + | array_9.finish();
|
163 + | }
|
164 + | }
|
165 + | array_7.finish();
|
166 + | }
|
167 + | crate::model::ConstrainedUnion::ConBMap(inner) => {
|
168 + | #[allow(unused_mut)]
|
169 + | let mut object_11 = object_71.key("conBMap").start_object();
|
170 + | for (key_12, value_13) in &inner.0 {
|
171 + | {
|
172 + | object_11.key(key_12.as_str()).string(value_13.as_str());
|
173 + | }
|
174 + | }
|
175 + | object_11.finish();
|
176 + | }
|
177 + | }
|
178 + | Ok(())
|
179 + | }
|