serde-ast

Crates.ioserde-ast
lib.rsserde-ast
version0.1.0-alpha.1
sourcesrc
created_at2024-09-18 21:18:08.754081
updated_at2024-09-18 21:18:08.754081
descriptionAn AST representation for serde serialization
homepagehttps://github.com/tinybeachthor/serde-redes
repositoryhttps://github.com/tinybeachthor/serde-redes
max_upload_size
id1379638
size38,369
Martin Toman (tinybeachthor)

documentation

README

serde-ast

Define an AST representation of serde serialization.

use serde::{Deserialize, Serialize};
use serde_ast::to_ast;

#[derive(Serialize, Deserialize)]
struct Example {
    hello: String,
}

let example = Example { hello: "World".to_string() };
let ast = to_ast(&example).expect("serialize to_ast");
println!("{}", ast);
Struct {
    name: "Example",
    len: 1,
    ops: [
        Field {
            key: "hello",
            value: Str(
                "World",
            ),
        },
    ],
}

Serializing the [Ast] is equivalent to directly serializing the original value.

// serialize the ast
let output = serde_json::to_string(&ast).expect("serde_json::to_string");
// serialize the value directly
let direct = serde_json::to_string(&example).expect("serde_json::to_string");
// the result is the same
assert_eq!(output, direct);
Commit count: 0

cargo fmt