Skip to content

Instantly share code, notes, and snippets.

@gf3
Created May 29, 2019 21:12
Show Gist options
  • Save gf3/ef1c9ef18ae17404ab0dffdfc15df57d to your computer and use it in GitHub Desktop.
Save gf3/ef1c9ef18ae17404ab0dffdfc15df57d to your computer and use it in GitHub Desktop.

Revisions

  1. gf3 created this gist May 29, 2019.
    29 changes: 29 additions & 0 deletions main.rs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    extern crate unidiff;

    use unidiff::PatchSet; // http://messense.github.io/unidiff-rs/unidiff/struct.PatchSet.html

    pub struct Printer {
    patch_set: PatchSet,
    }

    impl Printer {
    pub fn new(source: &str) -> Self {
    let mut patch_set = PatchSet::new();

    patch_set
    .parse(source)
    .ok()
    .expect("Error parsing source diff");

    Printer {
    patch_set,
    }
    }

    fn write_patches(&self, output: &mut dyn fmt::Write) {
    for patched_file in &self.patch_set {
    // ^^^^^^^^^^^^^^ cannot move out of borrowed content
    // ...do something with `patched_file`
    }
    }
    }