87 87 | }
|
88 88 | /// Returns true if this is a [`Union`](crate::types::ComplexUnion::Union).
|
89 89 | pub fn is_union(&self) -> bool {
|
90 90 | self.as_union().is_ok()
|
91 91 | }
|
92 92 | /// Returns true if the enum instance is the `Unknown` variant.
|
93 93 | pub fn is_unknown(&self) -> bool {
|
94 94 | matches!(self, Self::Unknown)
|
95 95 | }
|
96 96 | }
|
97 + | static COMPLEXUNION_SCHEMA_ID: ::aws_smithy_schema::ShapeId = ::aws_smithy_schema::ShapeId::from_static(
|
98 + | "smithy.protocoltests.rpcv2Cbor#ComplexUnion",
|
99 + | "smithy.protocoltests.rpcv2Cbor",
|
100 + | "ComplexUnion",
|
101 + | );
|
102 + | static COMPLEXUNION_MEMBER_COMPLEXSTRUCT: ::aws_smithy_schema::Schema = ::aws_smithy_schema::Schema::new_member(
|
103 + | ::aws_smithy_schema::ShapeId::from_static(
|
104 + | "smithy.protocoltests.rpcv2Cbor#ComplexUnion$complexStruct",
|
105 + | "smithy.protocoltests.rpcv2Cbor",
|
106 + | "ComplexUnion",
|
107 + | ),
|
108 + | ::aws_smithy_schema::ShapeType::Structure,
|
109 + | "complexStruct",
|
110 + | 0,
|
111 + | );
|
112 + | static COMPLEXUNION_MEMBER_STRUCTURE: ::aws_smithy_schema::Schema = ::aws_smithy_schema::Schema::new_member(
|
113 + | ::aws_smithy_schema::ShapeId::from_static(
|
114 + | "smithy.protocoltests.rpcv2Cbor#ComplexUnion$structure",
|
115 + | "smithy.protocoltests.rpcv2Cbor",
|
116 + | "ComplexUnion",
|
117 + | ),
|
118 + | ::aws_smithy_schema::ShapeType::Structure,
|
119 + | "structure",
|
120 + | 1,
|
121 + | );
|
122 + | static COMPLEXUNION_MEMBER_LIST: ::aws_smithy_schema::Schema = ::aws_smithy_schema::Schema::new_member(
|
123 + | ::aws_smithy_schema::ShapeId::from_static(
|
124 + | "smithy.protocoltests.rpcv2Cbor#ComplexUnion$list",
|
125 + | "smithy.protocoltests.rpcv2Cbor",
|
126 + | "ComplexUnion",
|
127 + | ),
|
128 + | ::aws_smithy_schema::ShapeType::List,
|
129 + | "list",
|
130 + | 2,
|
131 + | );
|
132 + | static COMPLEXUNION_MEMBER_MAP: ::aws_smithy_schema::Schema = ::aws_smithy_schema::Schema::new_member(
|
133 + | ::aws_smithy_schema::ShapeId::from_static(
|
134 + | "smithy.protocoltests.rpcv2Cbor#ComplexUnion$map",
|
135 + | "smithy.protocoltests.rpcv2Cbor",
|
136 + | "ComplexUnion",
|
137 + | ),
|
138 + | ::aws_smithy_schema::ShapeType::Map,
|
139 + | "map",
|
140 + | 3,
|
141 + | );
|
142 + | static COMPLEXUNION_MEMBER_UNION: ::aws_smithy_schema::Schema = ::aws_smithy_schema::Schema::new_member(
|
143 + | ::aws_smithy_schema::ShapeId::from_static(
|
144 + | "smithy.protocoltests.rpcv2Cbor#ComplexUnion$union",
|
145 + | "smithy.protocoltests.rpcv2Cbor",
|
146 + | "ComplexUnion",
|
147 + | ),
|
148 + | ::aws_smithy_schema::ShapeType::Union,
|
149 + | "union",
|
150 + | 4,
|
151 + | );
|
152 + | static COMPLEXUNION_SCHEMA: ::aws_smithy_schema::Schema = ::aws_smithy_schema::Schema::new_struct(
|
153 + | COMPLEXUNION_SCHEMA_ID,
|
154 + | ::aws_smithy_schema::ShapeType::Union,
|
155 + | &[
|
156 + | &COMPLEXUNION_MEMBER_COMPLEXSTRUCT,
|
157 + | &COMPLEXUNION_MEMBER_STRUCTURE,
|
158 + | &COMPLEXUNION_MEMBER_LIST,
|
159 + | &COMPLEXUNION_MEMBER_MAP,
|
160 + | &COMPLEXUNION_MEMBER_UNION,
|
161 + | ],
|
162 + | );
|
163 + | impl ComplexUnion {
|
164 + | /// The schema for this shape.
|
165 + | pub const SCHEMA: &'static ::aws_smithy_schema::Schema = &COMPLEXUNION_SCHEMA;
|
166 + | }
|
167 + | impl ::aws_smithy_schema::serde::SerializableStruct for ComplexUnion {
|
168 + | #[allow(unused_variables, clippy::diverging_sub_expression)]
|
169 + | fn serialize_members(
|
170 + | &self,
|
171 + | ser: &mut dyn ::aws_smithy_schema::serde::ShapeSerializer,
|
172 + | ) -> ::std::result::Result<(), ::aws_smithy_schema::serde::SerdeError> {
|
173 + | match self {
|
174 + | Self::ComplexStruct(val) => {
|
175 + | ser.write_struct(&COMPLEXUNION_MEMBER_COMPLEXSTRUCT, val)?;
|
176 + | }
|
177 + | Self::Structure(val) => {
|
178 + | ser.write_struct(&COMPLEXUNION_MEMBER_STRUCTURE, val)?;
|
179 + | }
|
180 + | Self::List(val) => {
|
181 + | ser.write_string_list(&COMPLEXUNION_MEMBER_LIST, val)?;
|
182 + | }
|
183 + | Self::Map(val) => {
|
184 + | ser.write_map(&COMPLEXUNION_MEMBER_MAP, &|ser: &mut dyn ::aws_smithy_schema::serde::ShapeSerializer| {
|
185 + | for (key, value) in val {
|
186 + | ser.write_string(&::aws_smithy_schema::prelude::STRING, key)?;
|
187 + | ser.write_integer(&::aws_smithy_schema::prelude::INTEGER, *value)?;
|
188 + | }
|
189 + | Ok(())
|
190 + | })?;
|
191 + | }
|
192 + | Self::Union(val) => {
|
193 + | ser.write_struct(&COMPLEXUNION_MEMBER_UNION, val)?;
|
194 + | }
|
195 + | Self::Unknown => return Err(::aws_smithy_schema::serde::SerdeError::custom("cannot serialize unknown union variant")),
|
196 + | }
|
197 + | Ok(())
|
198 + | }
|
199 + | }
|
200 + | impl ComplexUnion {
|
201 + | /// Deserializes this union from a [`ShapeDeserializer`].
|
202 + | pub fn deserialize(
|
203 + | deserializer: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer,
|
204 + | ) -> ::std::result::Result<Self, ::aws_smithy_schema::serde::SerdeError> {
|
205 + | let mut result: ::std::option::Option<Self> = ::std::option::Option::None;
|
206 + | #[allow(unused_variables, unreachable_code, clippy::single_match, clippy::match_single_binding)]
|
207 + | deserializer.read_struct(&COMPLEXUNION_SCHEMA, &mut |member, deser| {
|
208 + | result = ::std::option::Option::Some(match member.member_index() {
|
209 + | Some(0) => Self::ComplexStruct(crate::types::ComplexStruct::deserialize(deser)?),
|
210 + | Some(1) => Self::Structure(crate::types::SimpleStruct::deserialize(deser)?),
|
211 + | Some(2) => Self::List(deser.read_string_list(member)?),
|
212 + | Some(3) => Self::Map({
|
213 + | let mut container = std::collections::HashMap::new();
|
214 + | deser.read_map(member, &mut |key, deser| {
|
215 + | container.insert(key, deser.read_integer(member)?);
|
216 + | Ok(())
|
217 + | })?;
|
218 + | container
|
219 + | }),
|
220 + | Some(4) => Self::Union(crate::types::SimpleUnion::deserialize(deser)?),
|
221 + | _ => Self::Unknown,
|
222 + | });
|
223 + | Ok(())
|
224 + | })?;
|
225 + | result.ok_or_else(|| ::aws_smithy_schema::serde::SerdeError::custom("expected a union variant"))
|
226 + | }
|
227 + | }
|