macro_rules! cbor {
(@map {$($key:expr => $val:expr),*} $(,)?) => { ... };
(@map {$($key:expr => $val:expr),*} { $($nkey:tt)* } => $($next:tt)*) => { ... };
(@map {$($key:expr => $val:expr),*} [ $($nkey:tt)* ] => $($next:tt)*) => { ... };
(@map {$($key:expr => $val:expr),*} $nkey:expr => { $($nval:tt)* }, $($next:tt)*) => { ... };
(@map {$($key:expr => $val:expr),*} $nkey:expr => [ $($nval:tt)* ], $($next:tt)*) => { ... };
(@map {$($key:expr => $val:expr),*} $nkey:expr => $nval:expr, $($next:tt)*) => { ... };
(@seq [$($val:expr),*] $(,)?) => { ... };
(@seq [$($val:expr),*] { $($item:tt)* }, $($next:tt)*) => { ... };
(@seq [$($val:expr),*] [ $($item:tt)* ], $($next:tt)*) => { ... };
(@seq [$($val:expr),*] $item:expr, $($next:tt)*) => { ... };
({ $($next:tt)* }) => { ... };
([ $($next:tt)* ]) => { ... };
($val:expr) => { ... };
}
Expand description
Build a Value
conveniently.
The syntax should be intuitive if you are familiar with JSON. You can also
inline simple Rust expressions, including custom values that implement
serde::Serialize
. Note that this macro returns Result<Value, Error>
,
so you should handle the error appropriately.
use ciborium::cbor;
let value = cbor!({
"code" => 415,
"message" => null,
"continue" => false,
"extra" => { "numbers" => [8.2341e+4, 0.251425] },
}).unwrap();