pub fn edit_chunk_at_char<F>(
        &mut self,
        char_idx: usize,
        node_info: TextInfo,
        mut edit: F,
    ) -> (TextInfo, Option<(TextInfo, Arc<Node>)>)
    where
        F: FnMut(usize, TextInfo, &mut NodeText) -> (TextInfo, Option<(TextInfo, Arc<Node>)>),
    {
        match *self {
            Node::Leaf(ref mut leaf_text) => edit(char_idx, node_info, leaf_text),
            Node::Internal(ref mut children) => {
                // Compact leaf children if we're very close to maximum leaf
                // fragmentation.  This basically guards against excessive memory
                // ballooning when repeatedly appending to the end of a rope.
                // The constant here was arrived at experimentally, and is otherwise
                // fairly arbitrary.
                const FRAG_MIN_BYTES: usize = (MAX_BYTES * MIN_CHILDREN) + (MAX_BYTES / 32);
                if children.is_full()
                    && children.nodes()[0].is_leaf()
                    && (children.combined_info().bytes as usize) < FRAG_MIN_BYTES
                {
                    children.compact_leaves();
                }

                // Find the child we care about.
                let (child_i, acc_char_idx) = children.search_char_idx_only(char_idx);
                let info = children.info()[child_i];

                // Recurse into the child.
                let (l_info, residual) = Arc::make_mut(&mut children.nodes_mut()[child_i])
                    .edit_chunk_at_char(char_idx - acc_char_idx, info, edit);
                children.info_mut()[child_i] = l_info;

                // Handle the residual node if there is one and return.
                if let Some((r_info, r_node)) = residual {
                    if children.len() < MAX_CHILDREN {
                        children.insert(child_i + 1, (r_info, r_node));
                        (node_info - info + l_info + r_info, None)
                    } else {
                        let r = children.insert_split(child_i + 1, (r_info, r_node));
                        let r_info = r.combined_info();
                        (
                            children.combined_info(),
                            Some((r_info, Arc::new(Node::Internal(r)))),
                        )
                    }
                } else {
                    (node_info - info + l_info, None)
                }
            }
        }
    }
/// Fetches a chunk mutably, and allows it to be edited via a closure.
///
/// There are three parameters:
/// - char_idx: the chunk that contains this char is fetched,
/// - node_info: this is the text info of the node it's being called on.
///              This makes it a little awkward to call, but is needed since
///              it's actually the parent node that contains the text info,
///              so the info needs to be passed in.
/// - edit: the closure that receives the chunk and does the edits.
///
/// The closure is effectively the termination case for the recursion,
/// and takes essentially same parameters and returns the same things as
/// the method itself.  In particular, the closure receives the char offset
/// of char_idx within the given chunk and the TextInfo of the chunk.
/// The main difference is that it receives a NodeText instead of a node.
///
/// The closure is expected to return the updated text info of the node,
/// and if the node had to be split, then it also returns the right-hand
/// node along with its TextInfo as well.
///
/// The main method call will then return the total updated TextInfo for
/// the whole tree, and a new node only if the whole tree had to be split.
/// It is up to the caller to check for that new node, and handle it by
/// creating a new root with both the original node and the new node as
/// children.
Fetches a chunk mutably, and allows it to be edited via a closure.
There are three parameters:
char_idx: the chunk that contains this char is fetched,
node_info: this is the text info of the node it's being called on.
This makes it a little awkward to call, but is needed since
it's actually the parent node that contains the text info,
so the info needs to be passed in.
edit: the closure that receives the chunk and does the edits.

The closure is effectively the termination case for the recursion,
and takes essentially same parameters and returns the same things as
the method itself.  In particular, the closure receives the char offset
of char_idx within the given chunk and the TextInfo of the chunk.
The main difference is that it receives a NodeText instead of a node.

The closure is expected to return the updated text info of the node,
and if the node had to be split, then it also returns the right-hand
node along with its TextInfo as well.

The main method call will then return the total updated TextInfo for
the whole tree, and a new node only if the whole tree had to be split.
It is up to the caller to check for that new node, and handle it by
creating a new root with both the original node and the new node as
children.
Fetches a chunk mutably and allows it to be edited via a closure . There are three parameters : char_idx : the chunk that contains this char is fetched node_info : this is the text info of the node it ' s being called on . This makes it a little awkward to call but is needed since it ' s actually the parent node that contains the text info so the info needs to be passed in . edit : the closure that receives the chunk and does the edits . The closure is effectively the termination case for the recursion and takes essentially same parameters and returns the same things as the method itself . In particular the closure receives the char offset of char_idx within the given chunk and the TextInfo of the chunk . The main difference is that it receives a NodeText instead of a node . The closure is expected to return the updated text info of the node and if the node had to be split then it also returns the right - hand node along with its TextInfo as well . The main method call will then return the total updated TextInfo for the whole tree and a new node only if the whole tree had to be split . It is up to the caller to check for that new node and handle it by creating a new root with both the original node and the new node as children .
pub fn edit_chunk_at_char<F>(
        &mut self,
        char_idx: usize,
        node_info: TextInfo,
        mut edit: F,
    ) -> (TextInfo, Option<(TextInfo, Arc<Node>)>)
    where
        F: FnMut(usize, TextInfo, &mut NodeText) -> (TextInfo, Option<(TextInfo, Arc<Node>)>),
    {
        match *self {
            Node::Leaf(ref mut leaf_text) => edit(char_idx, node_info, leaf_text),
            Node::Internal(ref mut children) => {
                // Compact leaf children if we're very close to maximum leaf
                // fragmentation.  This basically guards against excessive memory
                // ballooning when repeatedly appending to the end of a rope.
                // The constant here was arrived at experimentally, and is otherwise
                // fairly arbitrary.
                const FRAG_MIN_BYTES: usize = (MAX_BYTES * MIN_CHILDREN) + (MAX_BYTES / 32);
                if children.is_full()
                    && children.nodes()[0].is_leaf()
                    && (children.combined_info().bytes as usize) < FRAG_MIN_BYTES
                {
                    children.compact_leaves();
                }
                // Find the child we care about.
                let (child_i, acc_char_idx) = children.search_char_idx_only(char_idx);
                let info = children.info()[child_i];
                // Recurse into the child.
                let (l_info, residual) = Arc::make_mut(&mut children.nodes_mut()[child_i])
                    .edit_chunk_at_char(char_idx - acc_char_idx, info, edit);
                children.info_mut()[child_i] = l_info;
                // Handle the residual node if there is one and return.
                if let Some((r_info, r_node)) = residual {
                    if children.len() < MAX_CHILDREN {
                        children.insert(child_i + 1, (r_info, r_node));
                        (node_info - info + l_info + r_info, None)
                    } else {
                        let r = children.insert_split(child_i + 1, (r_info, r_node));
                        let r_info = r.combined_info();
                        (
                            children.combined_info(),
                            Some((r_info, Arc::new(Node::Internal(r)))),
                        )
                    }
                } else {
                    (node_info - info + l_info, None)
                }
            }
        }
    }
pub fn edit_chunk_at_char < F > ( & mut self , char_idx : usize , node_info : TextInfo , mut edit : F , ) -> ( TextInfo , Option < ( TextInfo , Arc < Node > ) > ) where F : FnMut ( usize , TextInfo , & mut NodeText ) -> ( TextInfo , Option < ( TextInfo , Arc < Node > ) > ) , { match * self { Node :: Leaf ( ref mut leaf_text ) => edit ( char_idx , node_info , leaf_text ) , Node :: Internal ( ref mut children ) => { // Compact leaf children if we're very close to maximum leaf // fragmentation.  This basically guards against excessive memory // ballooning when repeatedly appending to the end of a rope. // The constant here was arrived at experimentally, and is otherwise // fairly arbitrary. const FRAG_MIN_BYTES : usize = ( MAX_BYTES * MIN_CHILDREN ) + ( MAX_BYTES / 32 ) ; if children . is_full ( ) && children . nodes ( ) [ 0 ] . is_leaf ( ) && ( children . combined_info ( ) . bytes as usize ) < FRAG_MIN_BYTES { children . compact_leaves ( ) ; } // Find the child we care about. let ( child_i , acc_char_idx ) = children . search_char_idx_only ( char_idx ) ; let info = children . info ( ) [ child_i ] ; // Recurse into the child. let ( l_info , residual ) = Arc :: make_mut ( & mut children . nodes_mut ( ) [ child_i ] ) . edit_chunk_at_char ( char_idx - acc_char_idx , info , edit ) ; children . info_mut ( ) [ child_i ] = l_info ; // Handle the residual node if there is one and return. if let Some ( ( r_info , r_node ) ) = residual { if children . len ( ) < MAX_CHILDREN { children . insert ( child_i + 1 , ( r_info , r_node ) ) ; ( node_info - info + l_info + r_info , None ) } else { let r = children . insert_split ( child_i + 1 , ( r_info , r_node ) ) ; let r_info = r . combined_info ( ) ; ( children . combined_info ( ) , Some ( ( r_info , Arc :: new ( Node :: Internal ( r ) ) ) ) , ) } } else { ( node_info - info + l_info , None ) } } } }
Fetches a chunk mutably, and allows it to be edited via a closure.
Fetches a chunk mutably and allows it to be edited via a closure .
&mut self
char_idx
usize
node_info
TextInfo
edit
F