pub fn rollback(&self, file_path: &Path) -> Result<(), Box<dyn Error>> {
        let mut rollback_edits = Vec::with_capacity(self.edits.len());

        // reverse the op and content for each edit.
        for edit in &self.edits {
            let new_op = match &edit.op {
                Operation::Insert => Operation::Delete,
                Operation::Delete => Operation::Insert,
                Operation::Replace => Operation::Replace,
            };

            rollback_edits.push(Edit {
                op: new_op,
                original: edit.modified.clone(),
                modified: edit.original.clone(),
            });
        }

        Diff::apply_edits(&rollback_edits, file_path)?;

        Ok(())
    }
/// Rollback a diff on a file by applying the reverse diff
Rollback a diff on a file by applying the reverse diff
Rollback a diff on a file by applying the reverse diff
pub fn rollback(&self, file_path: &Path) -> Result<(), Box<dyn Error>> {
        let mut rollback_edits = Vec::with_capacity(self.edits.len());
        // reverse the op and content for each edit.
        for edit in &self.edits {
            let new_op = match &edit.op {
                Operation::Insert => Operation::Delete,
                Operation::Delete => Operation::Insert,
                Operation::Replace => Operation::Replace,
            };
            rollback_edits.push(Edit {
                op: new_op,
                original: edit.modified.clone(),
                modified: edit.original.clone(),
            });
        }
        Diff::apply_edits(&rollback_edits, file_path)?;
        Ok(())
    }
pub fn rollback ( & self , file_path : & Path ) -> Result < ( ) , Box < dyn Error > > { let mut rollback_edits = Vec :: with_capacity ( self . edits . len ( ) ) ; // reverse the op and content for each edit. for edit in & self . edits { let new_op = match & edit . op { Operation :: Insert => Operation :: Delete , Operation :: Delete => Operation :: Insert , Operation :: Replace => Operation :: Replace , } ; rollback_edits . push ( Edit { op : new_op , original : edit . modified . clone ( ) , modified : edit . original . clone ( ) , } ) ; } Diff :: apply_edits ( & rollback_edits , file_path ) ? ; Ok ( ( ) ) }
Rollback a diff on a file by applying the reverse diff
Rollback a diff on a file by applying the reverse diff
&self
file_path
&Path
&self
file_path
&Path