[][src]Macro fog_pack::fogpack

macro_rules! fogpack {
    ($($fogpack:tt)+) => { ... };
}

Construct a fog_pack::Value from a JSON-like literal.

let value = fogpack!({
    "title": "First Post",
    "message": "This a test",
    "public": true,
    "index": 1,
    "tags": [
        "first",
        "test",
        "fogpack"
    ]
});

Variables or expressions can be interpolated into the literal. Any type interpolated into an array element or object value must implement Into<Value>, while any type interpolated into an object key must implement Into<String>. If these conditions are not met, the fogpack! macro will panic.

Importantly, a Vec or a slice must be of type Value to work, as the parser only accepts Vec/slices of type u8 (for the fogpack Binary type) or of type Value.

let title = "First Post";
let message = "This is a test";
let visibility = 3;
let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();
let taglist: Vec<Value> = 
    vec!["first", "test", "fogpack"]
    .iter()
    .map(|x| Value::from(*x))
    .collect();

let value = fogpack!({
    "title": title,
    "message": message,
    "public": visibility > 0,
    "time": Timestamp::from_sec(now.as_secs() as i64),
    "tags": taglist
});

Trailing commas are allowed inside both arrays and objects.

let value = fogpack!([
    "check",
    "out",
    "this",
    "comma -->",
]);