macro_rules! xpc {
($($xpc:tt)+) => { ... };
}Expand description
Construct an XPCObject from a JSON-like literal.
The xpc! macro allows you to construct XPCObject values with a syntax
similar to JSON. It supports signed and unsigned integers, which is a key
feature of XPC.
let value = xpc!({
"message": "hello",
"is_reply": true,
"signed_value": -42,
"unsigned_value": 42u64,
"payload": {
"items": [1, 2, 3],
"metadata": null // Becomes an empty string
}
});§Interpolation
You can interpolate variables and expressions directly into the macro.
Any interpolated value must implement the XpcConvertible trait.
let user_id = 1001u64;
let is_admin = false;
let request = xpc!({
"user_id": user_id,
"is_admin": is_admin,
"permissions": ["read", "write"],
});§Optional Fields and Merging
The macro supports optional fields using ? and dictionary merging
using :< for cleaner construction of complex objects.
let maybe_tag: Option<&str> = Some("important");
let base_config = xpc!({ "timeout": 5000u64 });
let message = xpc!({
"message_id": "msg-123",
"tag":? maybe_tag,
:< base_config,
});