diff --git a/blueprint-serde/src/lib.rs b/blueprint-serde/src/lib.rs index d58b1b96..2aedc1fd 100644 --- a/blueprint-serde/src/lib.rs +++ b/blueprint-serde/src/lib.rs @@ -1,3 +1,47 @@ +//! Compatibility crate for using the [Serde](https://docs.rs/serde) serialization frame with data from [`tangle_subxt`](https://docs.rs/tangle_subxt) +//! +//! This crate provides two primary functions: +//! +//! * [`to_field`] - Convert a [`Serialize`] type to a [`Field`] +//! * [`from_field`] - Convert a [`Field`] to a [`DeserializeOwned`] type +//! +//! # Examples +//! +//! ```rust +//! use gadget_blueprint_serde::{new_bounded_string, BoundedVec, Field}; +//! use serde::{Deserialize, Serialize}; +//! +//! #[derive(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); +//! ``` + #![cfg_attr(feature = "std", no_std)] mod de; @@ -66,7 +110,7 @@ where /// # Errors /// /// * Attempting to deserialize an [`UnsupportedType`](error::UnsupportedType) -/// * Attempting to deserialize non UTF-8 bytes into a [`String`] +/// * Attempting to deserialize non UTF-8 bytes into a [`String`](alloc::string::String) /// * Any type mismatch (e.g. attempting to deserialize [`Field::Int8`] into a [`char`]). /// /// # Examples