Struct Patch

Source
pub struct Patch<'a> {
    pub old: File<'a>,
    pub new: File<'a>,
    pub hunks: Vec<Hunk<'a>>,
}
Expand description

A complete patch summarizing the differences between two files

Fields§

§old: File<'a>

The file information of the - side of the diff, line prefix: ---

§new: File<'a>

The file information of the + side of the diff, line prefix: +++

§hunks: Vec<Hunk<'a>>

hunks of differences; each hunk shows one area where the files differ

Implementations§

Source§

impl<'a> Patch<'a>

Source

pub fn from_single(s: &'a str) -> Result<Self, ParseError<'a>>

Attempt to parse a patch from the given string.

§Example
let sample = "\
--- lao	2002-02-21 23:30:39.942229878 -0800
+++ tzu	2002-02-21 23:30:50.442260588 -0800
@@ -1,7 +1,6 @@
-The Way that can be told of is not the eternal Way;
-The name that can be named is not the eternal name.
 The Nameless is the origin of Heaven and Earth;
-The Named is the mother of all things.
+The named is the mother of all things.
+
 Therefore let there always be non-being,
 so we may see their subtlety,
 And let there always be being,
@@ -9,3 +8,6 @@
 The two are the same,
 But after they are produced,
 they have different names.
+They both may be called deep and profound.
+Deeper and more profound,
+The door of all subtleties!
\\ No newline at end of file\n";

let patch = Patch::from_single(sample)?;
assert_eq!(&patch.old.path, "lao");
assert_eq!(&patch.new.path, "tzu");
assert_eq!(patch.end_newline, false);
Source

pub fn from_multiple(s: &'a str) -> Result<Vec<Self>, ParseError<'a>>

Attempt to parse as many patches as possible from the given string. This is useful for when you have a complete diff of many files. String must contain at least one patch.

§Example
let sample = "\
diff --git a/src/generator/place_items.rs b/src/generator/place_items.rs
index 508f4e9..31a167e 100644
--- a/src/generator/place_items.rs
+++ b/src/generator/place_items.rs
@@ -233,7 +233,7 @@ impl<'a> GameGenerator<'a> {
         //     oooooooo
         //
         // x would pass all of the previous checks but get caught by this one
-        if grid.adjacent_positions(inner_room_tile).find(|&pt| grid.is_room_entrance(pt)).is_some() {
+        if grid.adjacent_positions(inner_room_tile).any(|&pt| grid.is_room_entrance(pt)) {
             return None;
         }

diff --git a/src/ui/level_screen.rs b/src/ui/level_screen.rs
index 81fe540..166bb2b 100644
--- a/src/ui/level_screen.rs
+++ b/src/ui/level_screen.rs
@@ -48,7 +48,7 @@ impl<'a, 'b> LevelScreen<'a, 'b> {
         // Find the empty position adjacent to this staircase. There should only be one.
         let map = self.world.read_resource::<FloorMap>();
         let tile_pos = map.world_to_tile_pos(pos);
-        let empty = map.grid().adjacent_positions(tile_pos).find(|&p| !map.grid().get(p).is_wall())
+        let empty = map.grid().adjacents(tile_pos).find(|t| !t.is_wall())
             .expect(\"bug: should be one empty position adjacent to a staircase\");
         empty.center(map.tile_size() as i32)
     }
@@ -64,7 +64,7 @@ impl<'a, 'b> LevelScreen<'a, 'b> {
         // Find the empty position adjacent to this staircase. There should only be one.
         let map = self.world.read_resource::<FloorMap>();
         let tile_pos = map.world_to_tile_pos(pos);
-        let empty = map.grid().adjacent_positions(tile_pos).find(|&p| !map.grid().get(p).is_wall())
+        let empty = map.grid().adjacents(tile_pos).find(|t| !t.is_wall())
             .expect(\"bug: should be one empty position adjacent to a staircase\");
         empty.center(map.tile_size() as i32)
     }\n";

let patches = Patch::from_multiple(sample)?;
assert_eq!(patches.len(), 2);

Trait Implementations§

Source§

impl<'a> Clone for Patch<'a>

Source§

fn clone(&self) -> Patch<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Patch<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Display for Patch<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> PartialEq for Patch<'a>

Source§

fn eq(&self, other: &Patch<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Eq for Patch<'a>

Source§

impl<'a> StructuralPartialEq for Patch<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Patch<'a>

§

impl<'a> RefUnwindSafe for Patch<'a>

§

impl<'a> Send for Patch<'a>

§

impl<'a> Sync for Patch<'a>

§

impl<'a> Unpin for Patch<'a>

§

impl<'a> UnwindSafe for Patch<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.