Macro json::extract [] [src]

macro_rules! extract {
    (
      let decoder = $dec: ident;
      let buffer  = $buf: expr;
      $($name: ident: $modus: ident. $typ: ty = $key: expr => $action: expr),+
    ) => { ... };
    (
      let decoder = $dec: ident;
      $($name: ident: $modus: ident. $typ: ty = $key: expr => $action: expr),+
    ) => { ... };
}

Macro to support extraction of subsets of JSON object fields.

Optionally extract! accepts a Utf8Buffer to use when decoding object keys.

Example:

#[macro_use] extern crate json;

use json::Decoder;

let mut d = Decoder::default(r#"{"x": 0, "y": 1}"#.chars());

let p = extract! {
    let decoder = d;
    x: req. u32 = "x" => d.from_json(),
    y: req. u32 = "y" => d.from_json()
}.unwrap();

assert_eq!(0, p.x);
assert_eq!(1, p.y);