aws_sdk_sagemaker/protocol_serde/
shape_metric_specification.rs1pub(crate) fn de_metric_specification<'a, I>(
3 tokens: &mut ::std::iter::Peekable<I>,
4) -> ::std::result::Result<Option<crate::types::MetricSpecification>, ::aws_smithy_json::deserialize::error::DeserializeError>
5where
6 I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
7{
8 let mut variant = None;
9 match tokens.next().transpose()? {
10 Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => return Ok(None),
11 Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => loop {
12 match tokens.next().transpose()? {
13 Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
14 Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
15 if let ::std::option::Option::Some(::std::result::Result::Ok(::aws_smithy_json::deserialize::Token::ValueNull { .. })) =
16 tokens.peek()
17 {
18 let _ = tokens.next().expect("peek returned a token")?;
19 continue;
20 }
21 let key = key.to_unescaped()?;
22 if key == "__type" {
23 ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
24 continue;
25 }
26 if variant.is_some() {
27 return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
28 "encountered mixed variants in union",
29 ));
30 }
31 variant = match key.as_ref() {
32 "Predefined" => Some(crate::types::MetricSpecification::Predefined(
33 crate::protocol_serde::shape_predefined_metric_specification::de_predefined_metric_specification(tokens)?.ok_or_else(
34 || ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'Predefined' cannot be null"),
35 )?,
36 )),
37 "Customized" => Some(crate::types::MetricSpecification::Customized(
38 crate::protocol_serde::shape_customized_metric_specification::de_customized_metric_specification(tokens)?.ok_or_else(
39 || ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'Customized' cannot be null"),
40 )?,
41 )),
42 _ => {
43 ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
44 Some(crate::types::MetricSpecification::Unknown)
45 }
46 };
47 }
48 other => {
49 return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
50 "expected object key or end object, found: {:?}",
51 other
52 )))
53 }
54 }
55 },
56 _ => {
57 return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
58 "expected start object or null",
59 ))
60 }
61 }
62 if variant.is_none() {
63 return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
64 "Union did not contain a valid variant.",
65 ));
66 }
67 Ok(variant)
68}