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

no-std gadget-blueprint-serde

Tangle Blueprints serde integration

3 unstable releases

new 0.2.0 Nov 17, 2024
0.1.1 Nov 8, 2024
0.1.0 Nov 5, 2024

#493 in Encoding

Download history 70/week @ 2024-10-30 185/week @ 2024-11-06 118/week @ 2024-11-13

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

MIT/Apache

49KB
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