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),+
) => { ... };
}
Expand description
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_codec_wasm;
use json_codec_wasm::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);