#blueprint #field #serialization #tangle #serde #gadget #person

no-std gadget-blueprint-serde

Tangle Blueprints serde integration

5 unstable releases

new 0.3.1 Dec 12, 2024
0.3.0 Dec 2, 2024
0.2.0 Nov 17, 2024
0.1.1 Nov 8, 2024
0.1.0 Nov 5, 2024

#560 in Encoding

Download history 241/week @ 2024-11-04 91/week @ 2024-11-11 108/week @ 2024-11-18 41/week @ 2024-11-25 256/week @ 2024-12-02 207/week @ 2024-12-09

681 downloads per month
Used in 4 crates (via gadget-sdk)

MIT/Apache

50KB
1.5K SLoC

Compatibility crate for using the Serde serialization frame with data from tangle_subxt

This crate provides two primary functions:

Examples

use gadget_blueprint_serde::{new_bounded_string, BoundedVec, Field};
use serde::{Deserialize, Serialize};

#[derive(PartialEq, Debug, Serialize, Deserialize)]
struct Person {
    name: String,
    age: u8,
}

let person = Person {
    name: String::from("John"),
    age: 40,
};

let expected = Field::Struct(
    new_bounded_string("Person"),
    Box::new(BoundedVec(vec![
        (
            new_bounded_string("name"),
            Field::String(new_bounded_string("John")),
        ),
        (new_bounded_string("age"), Field::Uint8(40)),
    ])),
);

// Convert our `Serialize` type to a `tangle_subxt::Field`
let field = gadget_blueprint_serde::to_field(&person).unwrap();
assert_eq!(expected, field);

// Convert our `tangle_subxt::Field` back to a `Person`
let person_deserialized: Person = gadget_blueprint_serde::from_field(field).unwrap();
assert_eq!(person, person_deserialized);

Dependencies

~25MB
~463K SLoC