macro_rules! pack {
($($tt:tt)*) => { ... };
}Expand description
Creates a shmp::Pack value using a JSON-like syntax.
This macro provides an intuitive way to construct Pack enums, which is especially
useful for creating complex, nested data structures for tests or dynamic configurations.
§Syntax
- Literals:
pack!(null),pack!(true),pack!(123),pack!(3.14),pack!("hello") - Arrays:
pack!([1, "two", false]). - Maps (Objects):
pack!({ "key": "value", "number": 123 }). - Expressions: Any valid Rust expression can be used as a value. To avoid ambiguity with the map syntax
pack!({ ... }), block expressions must be wrapped in parentheses (e.g.,({ let x = 1; x })) or use the dedicatedpack!(block { ... })syntax.
§Examples
let data = pack!({
"user_id": 1024,
"username": "shmp_user",
"tags": ["rust", "msgpack", "serde"],
"config": { "retries": 3, "timeout": null }
});
assert_eq!(data["username"], pack!("shmp_user"));
assert_eq!(data["tags"][0], pack!("rust"));