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]

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]

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]

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]

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]

Returns the root of the HashTree as an Option<&Box<HashTreeNode<T>>>.

pub fn find(&self, hash: T) -> Option<&HashTreeNode<T>>[src]

pub fn nodes(&self) -> usize[src]

Returns the number of nodes in the HashTree.

pub fn blocks(&self) -> usize[src]

Returns the number of blocks that were used to construct the HashTree.

Trait Implementations

impl<T: Clone, F: Clone> Clone for HashTree<T, F> where
    T: Debug + Clone + PartialEq,
    F: Fn(&[u8]) -> T, 
[src]

fn clone(&self) -> HashTree<T, F>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<T: Debug, F: Debug> Debug for HashTree<T, F> where
    T: Debug + Clone + PartialEq,
    F: Fn(&[u8]) -> T, 
[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<T, F> PartialEq<HashTree<T, F>> for HashTree<T, F> where
    T: Debug + Clone + PartialEq,
    F: Fn(&[u8]) -> T, 
[src]

fn eq(&self, other: &Self) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

Auto Trait Implementations

impl<T, F> RefUnwindSafe for HashTree<T, F> where
    F: RefUnwindSafe,
    T: RefUnwindSafe

impl<T, F> Send for HashTree<T, F> where
    F: Send,
    T: Send

impl<T, F> Sync for HashTree<T, F> where
    F: Sync,
    T: Sync

impl<T, F> Unpin for HashTree<T, F> where
    F: Unpin

impl<T, F> UnwindSafe for HashTree<T, F> where
    F: UnwindSafe,
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.