Struct hashtree::HashTree [−][src]
pub struct HashTree<T, F> where
T: Debug + Clone + PartialEq,
F: Fn(&[u8]) -> T, { /* fields omitted */ }
Expand description
A Merkle-tree.
Implementations
impl<T, F> HashTree<T, F> where
T: Debug + Clone + PartialEq,
F: Fn(&[u8]) -> T,
[src]
impl<T, F> HashTree<T, F> where
T: Debug + Clone + PartialEq,
F: Fn(&[u8]) -> T,
[src]pub fn new(strategy: HashStrategy<T, F>) -> Self
[src]
pub fn new(strategy: HashStrategy<T, F>) -> Self
[src]Constructs a new empty HashTree<T>
with a given
HashStrategy<T, F>
.
Examples
#![allow(dead_code)] use hashtree::{HashTree, HashStrategy}; const BLOCK_SIZE: usize = 4096; fn main() { let tree = HashTree::new( HashStrategy::new(BLOCK_SIZE, |data| { md5::compute(data) }) ); }
pub fn create<R>(data: &mut R, strategy: HashStrategy<T, F>) -> Result<Self> where
R: Read,
[src]
pub fn create<R>(data: &mut R, strategy: HashStrategy<T, F>) -> Result<Self> where
R: Read,
[src]Constructs a new HashTree<T, F>
from a mutable object
that implements the Read
trait and a HashStrategy<T, F>
.
Returns an Error
value if the function failed to read from
the given object.
Examples
#![allow(dead_code)] use hashtree::{HashTree, HashStrategy}; fn main() { let mut data = vec![0u8, 1u8]; let tree = HashTree::create( &mut data.as_slice(), HashStrategy::new(1, |x| md5::compute(x)) ); }
The example above uses a HashStrategy
that splits the data
into 1-byte blocks and computes their MD5 digests for the
HashTree
.
pub fn insert<R>(&mut self, data: &mut R) where
R: Read,
[src]
R: Read,
pub fn update(&mut self)
[src]
pub fn update(&mut self)
[src]Recomputes the hashes and nodes of the HashTree
. This method should be called
after you are done manually inserting data via the insert
method.
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
[src]Returns true
if the HashTree
is empty and false
otherwise.
Examples
#![allow(dead_code)] use hashtree::{HashTree, HashStrategy}; const BLOCK_SIZE: usize = 4096; fn main() { let tree = HashTree::new( HashStrategy::new(BLOCK_SIZE, |data| { md5::compute(data) }) ); assert_eq!(tree.is_empty(), true); }
pub fn root(&self) -> Option<&HashTreeNode<T>>
[src]
pub fn root(&self) -> Option<&HashTreeNode<T>>
[src]Returns the root of the HashTree
as an Option<&Box<HashTreeNode<T>>>
.
pub fn find(&self, hash: T) -> Option<&HashTreeNode<T>>
[src]
Trait Implementations
impl<T: Clone, F: Clone> Clone for HashTree<T, F> where
T: Debug + Clone + PartialEq,
F: Fn(&[u8]) -> T,
[src]
impl<T: Clone, F: Clone> Clone for HashTree<T, F> where
T: Debug + Clone + PartialEq,
F: Fn(&[u8]) -> T,
[src]impl<T: Debug, F: Debug> Debug for HashTree<T, F> where
T: Debug + Clone + PartialEq,
F: Fn(&[u8]) -> T,
[src]
impl<T: Debug, F: Debug> Debug for HashTree<T, F> where
T: Debug + Clone + PartialEq,
F: Fn(&[u8]) -> T,
[src]Auto Trait Implementations
impl<T, F> RefUnwindSafe for HashTree<T, F> where
F: RefUnwindSafe,
T: RefUnwindSafe,
F: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, F> Send for HashTree<T, F> where
F: Send,
T: Send,
F: Send,
T: Send,
impl<T, F> Sync for HashTree<T, F> where
F: Sync,
T: Sync,
F: Sync,
T: Sync,
impl<T, F> Unpin for HashTree<T, F> where
F: Unpin,
F: Unpin,
impl<T, F> UnwindSafe for HashTree<T, F> where
F: UnwindSafe,
T: UnwindSafe,
F: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more