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
681 downloads per month
Used in 4 crates
(via gadget-sdk)
50KB
1.5K
SLoC
Compatibility crate for using the Serde serialization frame with data from tangle_subxt
This crate provides two primary functions:
to_field
- Convert aSerialize
type to aField
from_field
- Convert aField
to aDeserializeOwned
type
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