Skip to content

Commit

Permalink
Merge pull request #4 from cspr-rad/serde
Browse files Browse the repository at this point in the history
add serde derive feature
  • Loading branch information
Avi-D-coder authored Apr 26, 2024
2 parents 979032a + bb0389f commit 760a4b7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ license = "MIT OR Apache-2.0"
[features]
default = ["std"]
std = []
serde = ["dep:serde"]

[profile.test]
opt-level = 3
Expand All @@ -18,9 +19,10 @@ overflow-checks = true
digest = "0.10"
bumpalo = "3"
ouroboros = "0.18"
serde = { version = "1", default-features = false, features = ["derive", "alloc"], optional = true }


[dev-dependencies]
sha2 = "0.10"
proptest-derive = { version = "0.4" }
proptest = { version = "1"}
proptest = { version = "1" }
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub use transaction::{
Entry, OccupiedEntry, Transaction, VacantEntry, VacantEntryEmptyTrie,
};

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct KeyHash(pub [u32; 8]);

Expand Down Expand Up @@ -72,6 +73,7 @@ impl PortableHash for KeyHash {
}
}

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct NodeHash {
pub bytes: [u8; 32],
Expand Down
2 changes: 2 additions & 0 deletions src/stored/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type Result<T, E = TrieError> = core::result::Result<T, E>;
/// A snapshot of the merkle trie
///
/// Contains visited nodes and unvisited nodes

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Snapshot<V> {
/// The last branch is the root of the trie if it exists.
Expand Down
5 changes: 5 additions & 0 deletions src/transaction/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use core::{fmt, iter, mem};

use crate::{hash::PortableHasher, stored, KeyHash, NodeHash, PortableHash, PortableUpdate};

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Default)]
pub enum TrieRoot<T> {
#[default]
Expand Down Expand Up @@ -38,6 +39,7 @@ impl From<TrieRoot<NodeHash>> for Option<NodeHash> {
}

/// A unmodified Node
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub enum Node<B, L> {
Branch(B),
Expand Down Expand Up @@ -115,6 +117,7 @@ impl<'s, V> StoredLeafRef<'s, V> {
}
}

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct BranchMask {
/// The index of the discriminant bit in the 256 bit hash key.
Expand Down Expand Up @@ -240,6 +243,7 @@ mod tests {
}
}

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Branch<NR> {
pub left: NR,
Expand Down Expand Up @@ -562,6 +566,7 @@ impl<V> Branch<NodeRef<V>> {
}
}

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Leaf<V> {
pub key_hash: KeyHash,
Expand Down

0 comments on commit 760a4b7

Please sign in to comment.