Macro json::object [] [src]

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

Macro to support declarative decoding into struct types.

Optionally object! accepts a Utf8Buffer to use when decoding object keys. Also decoder can be omitted in which case the macro expands to a lambda function expecting the decoder as argument (this form is useful for nested object! invocations).

Example:

struct Point {
    x: u32,
    y: u32
}

object! {
    let decoder = d;
    Point {
        x: req. "x" => Decoder::u32,
        y: req. "y" => Decoder::u32
    }
}