Crate wtfm_rs_serde

Crate wtfm_rs_serde 

Source
Expand description

§Introduction

This is the serde version of https://wtfm-rs.github.io/doc/wtfm_rs/.

§Why do we need a separate repo?

A separate repo allows a minimum Cargo.toml to only pulls in the basic serde and serde_json crates so that we can write tests and deep dive into the dependencies.

[package]
name = "wtfm-rs-tokio"
version = "0.1.0"
edition = "2024"

[dependencies]
serde = "1.0.228"
serde_json = "1.0.149"
├── serde v1.0.228
│   └── serde_core v1.0.228
└── serde_json v1.0.149
   ├── itoa v1.0.17
   ├── memchr v2.7.6
   ├── serde_core v1.0.228
   └── zmij v1.0.19

§Deserialize untyped data with from_str

let data = r#"
    {
        "name": "John Doe",
        "age": 43,
        "phones": [
            "+44 1234567",
            "+44 2345678"
        ]
    }"#;

let v: serde_json::Value = serde_json::from_str(data).expect("Valid data");
assert_eq!(format!("{}", v), "{\"age\":43,\"name\":\"John Doe\",\"phones\":[\"+44 1234567\",\"+44 2345678\"]}");

§json! macro

let john = serde_json::json!({
    "name": "John Doe",
    "age": 43,
    "phones": [
        "+44 1234567",
        "+44 2345678"
    ]
});

assert_eq!(format!("{}", john.to_string()), "{\"age\":43,\"name\":\"John Doe\",\"phones\":[\"+44 1234567\",\"+44 2345678\"]}");