#serde-json #create #traversal #style #boilerplate #macro #js-ts

serde_json_traversal

一个宏,用于创建遍历JSON(js/ts风格)的样板代码

2个不稳定版本

0.2.0 2021年8月12日
0.1.0 2020年8月16日

#1035 in 编码

Download history 207/week @ 2024-03-24 77/week @ 2024-03-31 370/week @ 2024-04-07 251/week @ 2024-04-14 197/week @ 2024-04-21 261/week @ 2024-04-28 357/week @ 2024-05-05 936/week @ 2024-05-12 716/week @ 2024-05-19 325/week @ 2024-05-26 84/week @ 2024-06-02 25/week @ 2024-06-09 866/week @ 2024-06-16 402/week @ 2024-06-23 268/week @ 2024-06-30 1224/week @ 2024-07-07

每月下载量 2,767

MIT/Apache

7KB

摘要

use serde_json_traversal::serde_json_traversal;

#[test]
fn success() {
    let json_obj = serde_json::json!({
        "foo": "bar",
        "bar": [
            "foo",
            "baz",
        ],
        "baz": {
            "foo": [
                "bar",
                {
                    "bar": "baz",
                },
            ],
        },
    });

   assert_eq!(serde_json_traversal!(json_obj => foo).unwrap(), "bar");
   assert_eq!(serde_json_traversal!(json_obj => bar => [0]).unwrap(), "foo");
   assert_eq!(serde_json_traversal!(json_obj => baz => foo => [0]).unwrap(), "bar");
   assert_eq!(serde_json_traversal!(json_obj => baz => foo => [1] => bar).unwrap(), "baz");

   let json_arr = serde_json::json!([
        "foo",
        {
            "bar": "baz",
        }
   ]);

   assert_eq!(serde_json_traversal!(json_arr => [0]).unwrap(), "foo");
   assert_eq!(serde_json_traversal!(json_arr => [1] => bar).unwrap(), "baz");
}

无运行时依赖