Skip to content

Commit

Permalink
📝 Add doc about serde and how to use
Browse files Browse the repository at this point in the history
  • Loading branch information
astariul committed Apr 12, 2023
1 parent db90f07 commit 33bd852
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::borrow::{Borrow, Cow};

impl Serialize for PatriciaSet {
/// In order to serialize a [PatriciaSet], make sure you installed the crate
/// with the feature `serde`.
///
/// For example, in your `Cargo.toml`:
/// ```toml
/// [dependencies]
/// patricia_tree = { version = "0.5.5", features = ["serde"] }
/// ```
///
/// Read more about serialization / deserialization at the [serde] crate.
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
Expand All @@ -14,6 +24,16 @@ impl Serialize for PatriciaSet {
}

impl<T: Serialize> Serialize for PatriciaMap<T> {
/// In order to serialize a [PatriciaMap], make sure you installed the crate
/// with the feature `serde`.
///
/// For example, in your `Cargo.toml`:
/// ```toml
/// [dependencies]
/// patricia_tree = { version = "0.5.5", features = ["serde"] }
/// ```
///
/// Read more about serialization / deserialization at the [serde] crate.
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
Expand Down Expand Up @@ -52,6 +72,16 @@ impl<T: Serialize> Serialize for Node<T> {
}

impl<'de> Deserialize<'de> for PatriciaSet {
/// In order to deserialize a [PatriciaSet], make sure you installed the crate
/// with the feature `serde`.
///
/// For example, in your `Cargo.toml`:
/// ```toml
/// [dependencies]
/// patricia_tree = { version = "0.5.5", features = ["serde"] }
/// ```
///
/// Read more about serialization / deserialization at the [serde] crate.
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
Expand All @@ -61,6 +91,16 @@ impl<'de> Deserialize<'de> for PatriciaSet {
}

impl<'de, T: Deserialize<'de>> Deserialize<'de> for PatriciaMap<T> {
/// In order to serialize a [PatriciaMap], make sure you installed the crate
/// with the feature `serde`.
///
/// For example, in your `Cargo.toml`:
/// ```toml
/// [dependencies]
/// patricia_tree = { version = "0.5.5", features = ["serde"] }
/// ```
///
/// Read more about serialization / deserialization at the [serde] crate.
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
Expand Down

0 comments on commit 33bd852

Please sign in to comment.