Skip to content

Commit

Permalink
feat(gadget-blueprint-serde): add crate docs (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serial-ATA authored Nov 8, 2024
1 parent e9a6446 commit ffe2f06
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion blueprint-serde/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ffe2f06

Please sign in to comment.