json_macros icon indicating copy to clipboard operation
json_macros copied to clipboard

JSON pattern macro

Open fenhl opened this issue 9 years ago • 3 comments

Feature request: a macro which works like json!, but in a pattern-matching context. Parentheses could be used to insert Rust's regular pattern matching. Example:

if let json_pat!({"isFoo": (Json::Boolean(flag))}) = json_blob {
    // matches {"isFoo": true} and {"isFoo": false}, and binds the value of the "isFoo" key to `flag`
    if flag { frob(); }
}

For additional convenience, it might also be useful if identifier bindings and the _ and .. syntaxes were available without parentheses.

fenhl avatar Mar 18 '15 22:03 fenhl