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§
source§impl<'a> Patch<'a>
impl<'a> Patch<'a>
sourcepub fn from_single(s: &'a str) -> Result<Self, ParseError<'a>>
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);
sourcepub fn from_multiple(s: &'a str) -> Result<Vec<Self>, ParseError<'a>>
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);