#serde #map #single #key #dictionary

serde-single-key-map

使用serde解包单个键映射

1个不稳定版本

0.1.0 2019年12月13日

#1290 in 编码

Download history 14/week @ 2023-10-29 13/week @ 2023-11-05 9/week @ 2023-11-12 12/week @ 2023-11-19 25/week @ 2023-11-26 7/week @ 2023-12-03 17/week @ 2023-12-10 15/week @ 2023-12-17 13/week @ 2023-12-24 11/week @ 2023-12-31 20/week @ 2024-01-07 20/week @ 2024-01-14 26/week @ 2024-01-21 13/week @ 2024-01-28 23/week @ 2024-02-04 35/week @ 2024-02-11

98 每月下载量
用于 shaco

MIT 许可协议

7KB
92

serde-single-key-map

使用serde解包单个键映射。

安装

将其添加到您的 Cargo.toml

[dependencies]
serde-single-key-map = "0.1"

用法

#[derive(Debug, Deserialize)]
struct Project {
    name: String,
    #[serde(deserialize_with = "serde_single_key_map::deserialize")]
    items: Vec<Item>,
}

#[derive(Debug, Deserialize)]
struct Item {
    name: String,
    source: String,
}

fn main() {
    let s = r#"{
        "name": "test",
        "items": {
            "item": [
            {
                "name": "name",
                "source": "name.rs"
            }
            ]
        }
        }"#;
    let project: Project = serde_json::from_str(s).expect("deserialize failed");
    assert_eq!(project.name, "test");
    assert_eq!(project.items.len(), 1);
    let item = &project.items[0];
    assert_eq!(item.name, "name");
    assert_eq!(item.source, "name.rs");
}

许可协议

本作品采用MIT许可协议发布。许可协议的副本可在LICENSE文件中找到。

依赖项

~110–350KB