#[doc(hidden)]
pub trait ItemInsert {
fn __item_insert(
self,
map: &mut std::collections::HashMap<String, crate::AttributeValue>,
key: &str,
);
}
impl<T: Into<crate::AttributeValue>> ItemInsert for T {
fn __item_insert(
self,
map: &mut std::collections::HashMap<String, crate::AttributeValue>,
key: &str,
) {
map.insert(key.to_string(), self.into());
}
}
impl<T: Into<crate::AttributeValue>> ItemInsert for Option<T> {
fn __item_insert(
self,
map: &mut std::collections::HashMap<String, crate::AttributeValue>,
key: &str,
) {
if let Some(v) = self {
map.insert(key.to_string(), v.into());
}
}
}
#[macro_export]
macro_rules! item {
() => {{
::std::collections::HashMap::<String, $crate::AttributeValue>::new()
}};
( $($rest:tt)+ ) => {{
#[allow(unused_mut)]
let mut map = ::std::collections::HashMap::<String, $crate::AttributeValue>::new();
$crate::__item_internal!(map, $($rest)+);
map
}};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __item_internal {
($map:ident, $key:expr => { $($inner:tt)* }, $($rest:tt)+) => {
$map.insert($key.to_string(), $crate::AttributeValue::M($crate::item! { $($inner)* }));
$crate::__item_internal!($map, $($rest)+);
};
($map:ident, $key:expr => { $($inner:tt)* } $(,)?) => {
$map.insert($key.to_string(), $crate::AttributeValue::M($crate::item! { $($inner)* }));
};
($map:ident, $key:expr => [ $($elem:expr),* $(,)? ], $($rest:tt)+) => {
$map.insert($key.to_string(), $crate::AttributeValue::L(vec![$($elem),*]));
$crate::__item_internal!($map, $($rest)+);
};
($map:ident, $key:expr => [ $($elem:expr),* $(,)? ] $(,)?) => {
$map.insert($key.to_string(), $crate::AttributeValue::L(vec![$($elem),*]));
};
($map:ident, $key:expr => $val:expr, $($rest:tt)+) => {
$crate::ItemInsert::__item_insert($val, &mut $map, $key);
$crate::__item_internal!($map, $($rest)+);
};
($map:ident, $key:expr => $val:expr $(,)?) => {
$crate::ItemInsert::__item_insert($val, &mut $map, $key);
};
}