aws_sdk_bedrockruntime/protocol_serde/
shape_content_block_delta.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub(crate) fn de_content_block_delta<'a, I>(
3    tokens: &mut ::std::iter::Peekable<I>,
4) -> ::std::result::Result<Option<crate::types::ContentBlockDelta>, ::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                        "text" => Some(crate::types::ContentBlockDelta::Text(
33                            ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
34                                .map(|s| s.to_unescaped().map(|u| u.into_owned()))
35                                .transpose()?
36                                .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'text' cannot be null"))?,
37                        )),
38                        "toolUse" => Some(crate::types::ContentBlockDelta::ToolUse(
39                            crate::protocol_serde::shape_tool_use_block_delta::de_tool_use_block_delta(tokens)?.ok_or_else(|| {
40                                ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'toolUse' cannot be null")
41                            })?,
42                        )),
43                        "toolResult" => Some(crate::types::ContentBlockDelta::ToolResult(
44                            crate::protocol_serde::shape_tool_result_blocks_delta::de_tool_result_blocks_delta(tokens)?.ok_or_else(|| {
45                                ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'toolResult' cannot be null")
46                            })?,
47                        )),
48                        "reasoningContent" => Some(crate::types::ContentBlockDelta::ReasoningContent(
49                            crate::protocol_serde::shape_reasoning_content_block_delta::de_reasoning_content_block_delta(tokens)?.ok_or_else(
50                                || ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'reasoningContent' cannot be null"),
51                            )?,
52                        )),
53                        "citation" => Some(crate::types::ContentBlockDelta::Citation(
54                            crate::protocol_serde::shape_citations_delta::de_citations_delta(tokens)?.ok_or_else(|| {
55                                ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'citation' cannot be null")
56                            })?,
57                        )),
58                        _ => {
59                            ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
60                            Some(crate::types::ContentBlockDelta::Unknown)
61                        }
62                    };
63                }
64                other => {
65                    return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
66                        "expected object key or end object, found: {other:?}"
67                    )))
68                }
69            }
70        },
71        _ => {
72            return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
73                "expected start object or null",
74            ))
75        }
76    }
77    if variant.is_none() {
78        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
79            "Union did not contain a valid variant.",
80        ));
81    }
82    Ok(variant)
83}