Struct patch::Patch

source ·
pub struct Patch<'a> {
    pub old: File<'a>,
    pub new: File<'a>,
    pub hunks: Vec<Hunk<'a>>,
    pub end_newline: bool,
}
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

§end_newline: bool

true if the last line of the file ends in a newline character

This will only be false if at the end of the patch we encounter the text: \ No newline at end of file

Implementations§

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);

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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.