1 个不稳定版本
使用旧的Rust 2015
0.1.0 | 2016年8月24日 |
---|
#1933 in 编码
5KB
57 行
为serde_json设计的可怕宏
类似于JavaScript风格的宏,用于轻松访问serde_json
值
#[macro_use] extern crate serde_wat;
extern crate serde_json;
use serde_json::from_str;
use serde_json::value::Value;
let a: Value = from_str(r#"{"b": {"c": 42}}"#).unwrap();
// Access unwrapping
assert_eq!(wat!(a.b.c as i64), 42);
// Safe access
assert_eq!(wat!(a.b as &str?), None);
// Testing
assert_eq!(wat!(a is bool), false);
示例
wat!(a.b.c as i64);
wat!(a as &mut Vec?);
wat!(a as &str);
wat!(a.b is i64);
wat!(a.b is &Map?);
wat!(a is &Map);
wat!(a.0 as bool);
lib.rs
:
为serde_json设计的可怕宏
类似于JavaScript风格的宏,用于轻松访问serde_json
值
#[macro_use] extern crate serde_wat;
extern crate serde_json;
use serde_json::from_str;
use serde_json::value::Value;
let a: Value = from_str(r#"{"b": {"c": 42}}"#).unwrap();
// Access unwrapping
assert_eq!(wat!(a.b.c as i64), 42);
// Safe access
assert_eq!(wat!(a.b as &str?), None);
// Testing
assert_eq!(wat!(a is bool), false);
示例
wat!(a.b.c as i64);
wat!(a as &mut Vec?);
wat!(a as &str);
wat!(a.b is i64);
wat!(a.b is &Map?);
wat!(a is &Map);
wat!(a.0 as bool);