Expand description
Compatibility crate for using the Serde serialization frame with data from tangle_subxt
This crate provides two primary functions:
to_field- Convert aSerializetype to aFieldfrom_field- Convert aFieldto aDeserializeOwnedtype
§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);Modules§
Structs§
- Bounded
Vec - ByteBuf
- Wrapper around
Vec<u8>to serialize and deserialize efficiently.
Enums§
Functions§
- from_
field - Derive an instance of type
Dfrom aField - new_
bounded_ string - to_
field - Derive a
Fieldfrom an instance of typeS