1
1
use libc:: { c_int, c_void} ;
2
+ use std:: marker:: PhantomData ;
2
3
use std:: path:: Path ;
3
4
use std:: ptr;
4
5
@@ -9,33 +10,37 @@ use crate::{raw, Blob, Buf, Diff, DiffDelta, DiffHunk, DiffLine, DiffOptions, Er
9
10
/// A structure representing the text changes in a single diff delta.
10
11
///
11
12
/// This is an opaque structure.
12
- pub struct Patch {
13
+ pub struct Patch < ' buffers > {
13
14
raw : * mut raw:: git_patch ,
15
+ buffers : PhantomData < & ' buffers ( ) > ,
14
16
}
15
17
16
- unsafe impl Send for Patch { }
18
+ unsafe impl < ' buffers > Send for Patch < ' buffers > { }
17
19
18
- impl Binding for Patch {
20
+ impl < ' buffers > Binding for Patch < ' buffers > {
19
21
type Raw = * mut raw:: git_patch ;
20
- unsafe fn from_raw ( raw : Self :: Raw ) -> Patch {
21
- Patch { raw : raw }
22
+ unsafe fn from_raw ( raw : Self :: Raw ) -> Self {
23
+ Patch {
24
+ raw : raw,
25
+ buffers : PhantomData ,
26
+ }
22
27
}
23
28
fn raw ( & self ) -> Self :: Raw {
24
29
self . raw
25
30
}
26
31
}
27
32
28
- impl Drop for Patch {
33
+ impl < ' buffers > Drop for Patch < ' buffers > {
29
34
fn drop ( & mut self ) {
30
35
unsafe { raw:: git_patch_free ( self . raw ) }
31
36
}
32
37
}
33
38
34
- impl Patch {
39
+ impl < ' buffers > Patch < ' buffers > {
35
40
/// Return a Patch for one file in a Diff.
36
41
///
37
42
/// Returns Ok(None) for an unchanged or binary file.
38
- pub fn from_diff ( diff : & Diff < ' _ > , idx : usize ) -> Result < Option < Patch > , Error > {
43
+ pub fn from_diff ( diff : & Diff < ' buffers > , idx : usize ) -> Result < Option < Self > , Error > {
39
44
let mut ret = ptr:: null_mut ( ) ;
40
45
unsafe {
41
46
try_call ! ( raw:: git_patch_from_diff( & mut ret, diff. raw( ) , idx) ) ;
@@ -45,12 +50,12 @@ impl Patch {
45
50
46
51
/// Generate a Patch by diffing two blobs.
47
52
pub fn from_blobs (
48
- old_blob : & Blob < ' _ > ,
53
+ old_blob : & Blob < ' buffers > ,
49
54
old_path : Option < & Path > ,
50
- new_blob : & Blob < ' _ > ,
55
+ new_blob : & Blob < ' buffers > ,
51
56
new_path : Option < & Path > ,
52
57
opts : Option < & mut DiffOptions > ,
53
- ) -> Result < Patch , Error > {
58
+ ) -> Result < Self , Error > {
54
59
let mut ret = ptr:: null_mut ( ) ;
55
60
let old_path = into_opt_c_string ( old_path) ?;
56
61
let new_path = into_opt_c_string ( new_path) ?;
@@ -69,12 +74,12 @@ impl Patch {
69
74
70
75
/// Generate a Patch by diffing a blob and a buffer.
71
76
pub fn from_blob_and_buffer (
72
- old_blob : & Blob < ' _ > ,
77
+ old_blob : & Blob < ' buffers > ,
73
78
old_path : Option < & Path > ,
74
- new_buffer : & [ u8 ] ,
79
+ new_buffer : & ' buffers [ u8 ] ,
75
80
new_path : Option < & Path > ,
76
81
opts : Option < & mut DiffOptions > ,
77
- ) -> Result < Patch , Error > {
82
+ ) -> Result < Self , Error > {
78
83
let mut ret = ptr:: null_mut ( ) ;
79
84
let old_path = into_opt_c_string ( old_path) ?;
80
85
let new_path = into_opt_c_string ( new_path) ?;
@@ -94,12 +99,12 @@ impl Patch {
94
99
95
100
/// Generate a Patch by diffing two buffers.
96
101
pub fn from_buffers (
97
- old_buffer : & [ u8 ] ,
102
+ old_buffer : & ' buffers [ u8 ] ,
98
103
old_path : Option < & Path > ,
99
- new_buffer : & [ u8 ] ,
104
+ new_buffer : & ' buffers [ u8 ] ,
100
105
new_path : Option < & Path > ,
101
106
opts : Option < & mut DiffOptions > ,
102
- ) -> Result < Patch , Error > {
107
+ ) -> Result < Self , Error > {
103
108
crate :: init ( ) ;
104
109
let mut ret = ptr:: null_mut ( ) ;
105
110
let old_path = into_opt_c_string ( old_path) ?;
@@ -120,7 +125,7 @@ impl Patch {
120
125
}
121
126
122
127
/// Get the DiffDelta associated with the Patch.
123
- pub fn delta ( & self ) -> DiffDelta < ' _ > {
128
+ pub fn delta ( & self ) -> DiffDelta < ' buffers > {
124
129
unsafe { Binding :: from_raw ( raw:: git_patch_get_delta ( self . raw ) as * mut _ ) }
125
130
}
126
131
@@ -146,7 +151,7 @@ impl Patch {
146
151
}
147
152
148
153
/// Get a DiffHunk and its total line count from the Patch.
149
- pub fn hunk ( & self , hunk_idx : usize ) -> Result < ( DiffHunk < ' _ > , usize ) , Error > {
154
+ pub fn hunk ( & self , hunk_idx : usize ) -> Result < ( DiffHunk < ' buffers > , usize ) , Error > {
150
155
let mut ret = ptr:: null ( ) ;
151
156
let mut lines = 0 ;
152
157
unsafe {
@@ -167,7 +172,7 @@ impl Patch {
167
172
& self ,
168
173
hunk_idx : usize ,
169
174
line_of_hunk : usize ,
170
- ) -> Result < DiffLine < ' _ > , Error > {
175
+ ) -> Result < DiffLine < ' buffers > , Error > {
171
176
let mut ret = ptr:: null ( ) ;
172
177
unsafe {
173
178
try_call ! ( raw:: git_patch_get_line_in_hunk(
@@ -216,7 +221,7 @@ impl Patch {
216
221
}
217
222
}
218
223
219
- impl std:: fmt:: Debug for Patch {
224
+ impl < ' buffers > std:: fmt:: Debug for Patch < ' buffers > {
220
225
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> Result < ( ) , std:: fmt:: Error > {
221
226
let mut ds = f. debug_struct ( "Patch" ) ;
222
227
ds. field ( "delta" , & self . delta ( ) )
0 commit comments