Function bao::decode::hash_from_outboard_encoded_nostd [−][src]
pub fn hash_from_outboard_encoded_nostd<F1, F2, E>(
content_read_exact_fn: F1,
outboard_read_exact_fn: F2
) -> Result<Hash, E> where
F1: FnOnce(&mut [u8]) -> Result<(), E>,
F2: FnMut(&mut [u8]) -> Result<(), E>,
Given an outboard encoding, quickly determine the root hash by reading just the root node.
Depending on the content length, the outboard_read_exact_fn
callback will be called one or
two times, and the content_read_exact_fn
will be called either one time or not at all.
Example
let input = b"foobar"; let (hash1, outboard) = bao::encode::encode_outboard_to_vec(input); let mut content_reader = &input[..]; let mut outboard_reader = &*outboard; let hash2 = bao::decode::hash_from_outboard_encoded_nostd( |buf| { let take = buf.len(); buf.copy_from_slice(&content_reader[..take]); content_reader = &content_reader[take..]; Ok::<(), ()>(()) }, |buf| { let take = buf.len(); buf.copy_from_slice(&outboard_reader[..take]); outboard_reader = &outboard_reader[take..]; Ok::<(), ()>(()) }, ).unwrap(); assert_eq!(hash1, hash2);