From 7fb354cf5561f6e2f3f0825279654d11af1b78fc Mon Sep 17 00:00:00 2001 From: sinu <65924192+sinui0@users.noreply.github.com> Date: Mon, 12 Aug 2024 13:29:33 -0700 Subject: [PATCH] feat: serde feature --- Cargo.toml | 4 +++- src/merkle_proof.rs | 1 + src/merkle_tree.rs | 1 + src/partial_tree.rs | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index d23761e..1bc1966 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,13 +8,14 @@ license = "Apache-2.0/MIT" repository = "https://github.com/antouhou/rs-merkle" documentation = "https://docs.rs/rs_merkle/" readme = "README.md" -keywords = ["merkle", "tree", "proof", "hash", "multiproof",] +keywords = ["merkle", "tree", "proof", "hash", "multiproof"] exclude = ["/ci/*", "/scripts/*", "/.github/*", "/bors.toml"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] sha2 = { version = "0.10", default-features = false } +serde = { version = "1", optional = true, features = ["derive"] } # standard crate data is left out [dev-dependencies] @@ -23,3 +24,4 @@ rayon = "1.5.1" [features] default = ['std'] std = ["sha2/std"] +serde = ["dep:serde"] diff --git a/src/merkle_proof.rs b/src/merkle_proof.rs index 153c670..3f294a6 100644 --- a/src/merkle_proof.rs +++ b/src/merkle_proof.rs @@ -47,6 +47,7 @@ use core::convert::TryFrom; /// /// [`Hasher`]: crate::Hasher /// [`algorithms::Sha256`]: crate::algorithms::Sha256 +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct MerkleProof { proof_hashes: Vec, } diff --git a/src/merkle_tree.rs b/src/merkle_tree.rs index e166d4d..952e3da 100644 --- a/src/merkle_tree.rs +++ b/src/merkle_tree.rs @@ -15,6 +15,7 @@ use crate::{ /// roll back to any previously committed state of the tree. This scenario is similar to Git and /// can be found in databases and file systems. #[derive(Clone)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct MerkleTree { current_working_tree: PartialTree, history: Vec>, diff --git a/src/partial_tree.rs b/src/partial_tree.rs index 0687407..6f4eae3 100644 --- a/src/partial_tree.rs +++ b/src/partial_tree.rs @@ -12,6 +12,7 @@ type PartialTreeLayer = Vec<(usize, H)>; /// [`MerkleTree`]: crate::MerkleTree /// [`MerkleProof`]: crate::MerkleProof #[derive(Clone)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct PartialTree { layers: Vec>, }