1#[doc(hidden)]
6pub trait ItemInsert {
7 fn __item_insert(
8 self,
9 map: &mut std::collections::HashMap<String, crate::AttributeValue>,
10 key: &str,
11 );
12}
13
14impl<T: Into<crate::AttributeValue>> ItemInsert for T {
15 fn __item_insert(
16 self,
17 map: &mut std::collections::HashMap<String, crate::AttributeValue>,
18 key: &str,
19 ) {
20 map.insert(key.to_string(), self.into());
21 }
22}
23
24impl<T: Into<crate::AttributeValue>> ItemInsert for Option<T> {
25 fn __item_insert(
26 self,
27 map: &mut std::collections::HashMap<String, crate::AttributeValue>,
28 key: &str,
29 ) {
30 if let Some(v) = self {
31 map.insert(key.to_string(), v.into());
32 }
33 }
34}
35
36#[macro_export]
80macro_rules! item {
81 () => {{
83 ::std::collections::HashMap::<String, $crate::AttributeValue>::new()
84 }};
85 ( $($rest:tt)+ ) => {{
87 #[allow(unused_mut)]
88 let mut map = ::std::collections::HashMap::<String, $crate::AttributeValue>::new();
89 $crate::__item_internal!(map, $($rest)+);
90 map
91 }};
92}
93
94#[doc(hidden)]
95#[macro_export]
96macro_rules! __item_internal {
97 ($map:ident, $key:expr => { $($inner:tt)* }, $($rest:tt)+) => {
99 $map.insert($key.to_string(), $crate::AttributeValue::M($crate::item! { $($inner)* }));
100 $crate::__item_internal!($map, $($rest)+);
101 };
102 ($map:ident, $key:expr => { $($inner:tt)* } $(,)?) => {
104 $map.insert($key.to_string(), $crate::AttributeValue::M($crate::item! { $($inner)* }));
105 };
106 ($map:ident, $key:expr => [ $($elem:expr),* $(,)? ], $($rest:tt)+) => {
108 $map.insert($key.to_string(), $crate::AttributeValue::L(vec![$($elem),*]));
109 $crate::__item_internal!($map, $($rest)+);
110 };
111 ($map:ident, $key:expr => [ $($elem:expr),* $(,)? ] $(,)?) => {
113 $map.insert($key.to_string(), $crate::AttributeValue::L(vec![$($elem),*]));
114 };
115 ($map:ident, $key:expr => $val:expr, $($rest:tt)+) => {
117 $crate::ItemInsert::__item_insert($val, &mut $map, $key);
118 $crate::__item_internal!($map, $($rest)+);
119 };
120 ($map:ident, $key:expr => $val:expr $(,)?) => {
122 $crate::ItemInsert::__item_insert($val, &mut $map, $key);
123 };
124}