fn modify_leaf_at_index(t: &mut RoseHashTree, idx: usize, h: Digest) -> Option<(Path, Digest)> {
        fn go_rec(
            t: &mut RoseHashTree,
            idx: usize,
            new_hash: Digest,
            path: &mut Path,
        ) -> Result<(Path, Digest), usize> {
            match t {
                RoseHashTree::Leaf(ref mut hash) if idx == 0 => {
                    let old_hash = std::mem::replace(hash, new_hash);
                    Ok((path.clone(), old_hash))
                }
                RoseHashTree::Leaf(_) => Err(idx - 1),
                RoseHashTree::Fork { children, .. } => {
                    let mut i = idx;
                    for (label, mut child) in children.iter_mut() {
                        path.push(label.clone());
                        match go_rec(&mut child, i, new_hash.clone(), path) {
                            Ok(result) => return Ok(result),
                            Err(new_index) => i = new_index,
                        }
                        path.pop();
                    }
                    Err(i)
                }
            }
        }

        let mut path = Path::new(vec![]);

        match go_rec(t, idx, h, &mut path) {
            Ok(result) => {
                rehash(t);
                Some(result)
            }
            Err(_) => None,
        }
    }
/// Modify the leaf at the given index. The leaves are counted according to
/// their in-order traveral.
Modify the leaf at the given index. The leaves are counted according to
their in-order traveral.
Modify the leaf at the given index . The leaves are counted according to their in - order traveral .
fn modify_leaf_at_index(t: &mut RoseHashTree, idx: usize, h: Digest) -> Option<(Path, Digest)> {
        fn go_rec(
            t: &mut RoseHashTree,
            idx: usize,
            new_hash: Digest,
            path: &mut Path,
        ) -> Result<(Path, Digest), usize> {
            match t {
                RoseHashTree::Leaf(ref mut hash) if idx == 0 => {
                    let old_hash = std::mem::replace(hash, new_hash);
                    Ok((path.clone(), old_hash))
                }
                RoseHashTree::Leaf(_) => Err(idx - 1),
                RoseHashTree::Fork { children, .. } => {
                    let mut i = idx;
                    for (label, mut child) in children.iter_mut() {
                        path.push(label.clone());
                        match go_rec(&mut child, i, new_hash.clone(), path) {
                            Ok(result) => return Ok(result),
                            Err(new_index) => i = new_index,
                        }
                        path.pop();
                    }
                    Err(i)
                }
            }
        }
        let mut path = Path::new(vec![]);
        match go_rec(t, idx, h, &mut path) {
            Ok(result) => {
                rehash(t);
                Some(result)
            }
            Err(_) => None,
        }
    }
fn modify_leaf_at_index ( t : & mut RoseHashTree , idx : usize , h : Digest ) -> Option < ( Path , Digest ) > { fn go_rec ( t : & mut RoseHashTree , idx : usize , new_hash : Digest , path : & mut Path , ) -> Result < ( Path , Digest ) , usize > { match t { RoseHashTree :: Leaf ( ref mut hash ) if idx == 0 => { let old_hash = std :: mem :: replace ( hash , new_hash ) ; Ok ( ( path . clone ( ) , old_hash ) ) } RoseHashTree :: Leaf ( _ ) => Err ( idx - 1 ) , RoseHashTree :: Fork { children , .. } => { let mut i = idx ; for ( label , mut child ) in children . iter_mut ( ) { path . push ( label . clone ( ) ) ; match go_rec ( & mut child , i , new_hash . clone ( ) , path ) { Ok ( result ) => return Ok ( result ) , Err ( new_index ) => i = new_index , } path . pop ( ) ; } Err ( i ) } } } let mut path = Path :: new ( vec ! [ ] ) ; match go_rec ( t , idx , h , & mut path ) { Ok ( result ) => { rehash ( t ) ; Some ( result ) } Err ( _ ) => None , } }
Modify the leaf at the given index.
Modify the leaf at the given index .
t
&mut RoseHashTree
idx
usize
h
Digest
t
&mut RoseHashTree
idx
usize
h
Digest