Remove unknown fields

This commit is contained in:
Julien Cretin
2020-05-13 11:09:32 +02:00
parent 479de32a95
commit ca6f910c26
4 changed files with 49 additions and 75 deletions

View File

@@ -41,31 +41,20 @@ macro_rules! cbor_map_options {
};
( $( $key:expr => $value:expr ),* ) => {
{
let mut _map = ::alloc::collections::BTreeMap::<_, $crate::values::Value>::new();
extend_cbor_map_options! ( &mut _map, $( $key => $value, )* );
$crate::values::Value::Map(_map)
}
};
}
#[macro_export]
macro_rules! extend_cbor_map_options {
// Add trailing comma if missing.
( &mut $map:expr, $( $key:expr => $value:expr ),+ ) => {
extend_cbor_map_options! ( &mut $map, $($key => $value,)+ )
};
( &mut $map:expr, $( $key:expr => $value:expr, )* ) => {
{
// The import is unused if the list is empty.
#[allow(unused_imports)]
use $crate::values::{IntoCborKey, IntoCborValueOption};
let mut _map = ::alloc::collections::BTreeMap::<_, $crate::values::Value>::new();
$(
if let Some(val) = $value.into_cbor_value_option() {
$map.insert($key.into_cbor_key(), val);
{
let opt: Option<$crate::values::Value> = $value.into_cbor_value_option();
if let Some(val) = opt {
_map.insert($key.into_cbor_key(), val);
}
}
)*
$crate::values::Value::Map(_map)
}
};
}