macro_rules! msgpack {
($( $tt: tt )*) => { ... };
}
Expand description
Constructs a Value from literal.
ยงExample
let obj = msgpack!(
// array literal
[
// numeric literals
0,
-42,
3.14,
2.71f32,
// actually any expression is allowed (as long as it's a supported type)
1 + 2 + 3,
// boolean
true,
false,
// nil is a keyword denoting the nil object
nil,
// string literal to make a string object
"hello",
// Use an expression of [Bin] type to create a binary object
Bin(vec![0xDE, 0xAD, 0xBE, 0xEF]),
// map object
{ "any value in key": nil },
{ 0: 1, "trailing comma is ok": nil, }
]
);
assert_eq!(
obj,
Value::Array(vec![
Value::Int(Int::from(0)),
Value::Int(Int::from(-42)),
Value::F64(3.14),
Value::F32(2.71),
Value::Int(Int::from(6)),
Value::Bool(true),
Value::Bool(false),
Value::Nil,
Value::Str(Str("hello".to_owned().into_bytes())),
Value::Bin(Bin(vec![0xDE, 0xAD, 0xBE, 0xEF])),
Value::Map(vec![(
Value::Str(Str("any value in key".to_owned().into_bytes())),
Value::Nil
),]),
Value::Map(vec![
(Value::Int(Int::from(0)), Value::Int(Int::from(1))),
(
Value::Str(Str("trailing comma is ok".to_owned().into_bytes())),
Value::Nil
),
])
])
)