pub fn apply(&mut self, target: &Node) -> Result<Overlay> {
        if target.overlay == Overlay::UpperRemoval {
            return self.remove(target, false);
        }

        if target.overlay == Overlay::UpperOpaque {
            self.remove(target, true)?;
            // Continue to handle child nodes
        }

        let target_paths = target.path_vec();
        let target_paths_len = target_paths.len();
        let depth = self.node.path_vec().len();

        // Don't search if path recursive depth out of target path
        if depth < target_paths_len {
            // TODO: Search child by binary search
            for child in self.children.iter_mut() {
                // Skip if path component name not match
                if target_paths[depth] != child.node.name() {
                    continue;
                }
                // Modifications: Replace the node
                if depth == target_paths_len - 1 {
                    let mut node = target.clone();
                    node.overlay = Overlay::UpperModification;
                    *child = Tree {
                        node,
                        children: child.children.clone(),
                    };
                    return Ok(Overlay::UpperModification);
                }
                if child.node.is_dir() {
                    // Search the node recursively
                    let overlay = child.apply(target)?;
                    if overlay != Overlay::Lower {
                        return Ok(overlay);
                    }
                }
            }
        }

        // Additions: Add new node to children
        if depth == target_paths_len - 1 && target_paths[depth - 1] == self.node.name() {
            let mut node = target.clone();
            node.overlay = Overlay::UpperAddition;
            self.children.push(Tree {
                node,
                children: Vec::new(),
            });
            return Ok(Overlay::UpperAddition);
        }

        Ok(Overlay::Lower)
    }
/// Apply new node (upper layer) to node tree (lower layer),
/// include change types Additions, Modifications, Removals and Opaques
Apply new node (upper layer) to node tree (lower layer),
include change types Additions, Modifications, Removals and Opaques
Apply new node ( upper layer ) to node tree ( lower layer ) include change types Additions Modifications Removals and Opaques
pub fn apply(&mut self, target: &Node) -> Result<Overlay> {
        if target.overlay == Overlay::UpperRemoval {
            return self.remove(target, false);
        }
        if target.overlay == Overlay::UpperOpaque {
            self.remove(target, true)?;
            // Continue to handle child nodes
        }
        let target_paths = target.path_vec();
        let target_paths_len = target_paths.len();
        let depth = self.node.path_vec().len();
        // Don't search if path recursive depth out of target path
        if depth < target_paths_len {
            // TODO: Search child by binary search
            for child in self.children.iter_mut() {
                // Skip if path component name not match
                if target_paths[depth] != child.node.name() {
                    continue;
                }
                // Modifications: Replace the node
                if depth == target_paths_len - 1 {
                    let mut node = target.clone();
                    node.overlay = Overlay::UpperModification;
                    *child = Tree {
                        node,
                        children: child.children.clone(),
                    };
                    return Ok(Overlay::UpperModification);
                }
                if child.node.is_dir() {
                    // Search the node recursively
                    let overlay = child.apply(target)?;
                    if overlay != Overlay::Lower {
                        return Ok(overlay);
                    }
                }
            }
        }
        // Additions: Add new node to children
        if depth == target_paths_len - 1 && target_paths[depth - 1] == self.node.name() {
            let mut node = target.clone();
            node.overlay = Overlay::UpperAddition;
            self.children.push(Tree {
                node,
                children: Vec::new(),
            });
            return Ok(Overlay::UpperAddition);
        }
        Ok(Overlay::Lower)
    }
pub fn apply ( & mut self , target : & Node ) -> Result < Overlay > { if target . overlay == Overlay :: UpperRemoval { return self . remove ( target , false ) ; } if target . overlay == Overlay :: UpperOpaque { self . remove ( target , true ) ? ; // Continue to handle child nodes } let target_paths = target . path_vec ( ) ; let target_paths_len = target_paths . len ( ) ; let depth = self . node . path_vec ( ) . len ( ) ; // Don't search if path recursive depth out of target path if depth < target_paths_len { // TODO: Search child by binary search for child in self . children . iter_mut ( ) { // Skip if path component name not match if target_paths [ depth ] != child . node . name ( ) { continue ; } // Modifications: Replace the node if depth == target_paths_len - 1 { let mut node = target . clone ( ) ; node . overlay = Overlay :: UpperModification ; * child = Tree { node , children : child . children . clone ( ) , } ; return Ok ( Overlay :: UpperModification ) ; } if child . node . is_dir ( ) { // Search the node recursively let overlay = child . apply ( target ) ? ; if overlay != Overlay :: Lower { return Ok ( overlay ) ; } } } } // Additions: Add new node to children if depth == target_paths_len - 1 && target_paths [ depth - 1 ] == self . node . name ( ) { let mut node = target . clone ( ) ; node . overlay = Overlay :: UpperAddition ; self . children . push ( Tree { node , children : Vec :: new ( ) , } ) ; return Ok ( Overlay :: UpperAddition ) ; } Ok ( Overlay :: Lower ) }
Apply new node (upper layer) to node tree (lower layer),
include change types Additions, Modifications, Removals and Opaques
Apply new node ( upper layer ) to node tree ( lower layer ) include change types Additions Modifications Removals and Opaques
&mut self
target
&Node
&mut self
target
&Node