@@ -17,12 +17,16 @@ pub struct Commit<'repo> {
17
17
}
18
18
19
19
/// An iterator over the parent commits of a commit.
20
+ ///
21
+ /// Aborts iteration when a commit cannot be found
20
22
pub struct Parents < ' commit , ' repo : ' commit > {
21
23
range : Range < usize > ,
22
24
commit : & ' commit Commit < ' repo > ,
23
25
}
24
26
25
27
/// An iterator over the parent commits' ids of a commit.
28
+ ///
29
+ /// Aborts iteration when a commit cannot be found
26
30
pub struct ParentIds < ' commit > {
27
31
range : Range < usize > ,
28
32
commit : & ' commit Commit < ' commit > ,
@@ -81,7 +85,7 @@ impl<'repo> Commit<'repo> {
81
85
let bytes = unsafe {
82
86
:: opt_bytes ( self , raw:: git_commit_message ( & * self . raw ) )
83
87
} ;
84
- bytes. map ( |b| str:: from_utf8 ( b) . unwrap ( ) )
88
+ bytes. and_then ( |b| str:: from_utf8 ( b) . ok ( ) )
85
89
}
86
90
87
91
/// Get the full raw message of a commit.
@@ -273,33 +277,37 @@ impl<'repo> ::std::fmt::Debug for Commit<'repo> {
273
277
}
274
278
}
275
279
280
+ /// Aborts iteration when a commit cannot be found
276
281
impl < ' repo , ' commit > Iterator for Parents < ' commit , ' repo > {
277
282
type Item = Commit < ' repo > ;
278
283
fn next ( & mut self ) -> Option < Commit < ' repo > > {
279
- self . range . next ( ) . map ( |i| self . commit . parent ( i) . unwrap ( ) )
284
+ self . range . next ( ) . and_then ( |i| self . commit . parent ( i) . ok ( ) )
280
285
}
281
286
fn size_hint ( & self ) -> ( usize , Option < usize > ) { self . range . size_hint ( ) }
282
287
}
283
288
289
+ /// Aborts iteration when a commit cannot be found
284
290
impl < ' repo , ' commit > DoubleEndedIterator for Parents < ' commit , ' repo > {
285
291
fn next_back ( & mut self ) -> Option < Commit < ' repo > > {
286
- self . range . next_back ( ) . map ( |i| self . commit . parent ( i) . unwrap ( ) )
292
+ self . range . next_back ( ) . and_then ( |i| self . commit . parent ( i) . ok ( ) )
287
293
}
288
294
}
289
295
290
296
impl < ' repo , ' commit > ExactSizeIterator for Parents < ' commit , ' repo > { }
291
297
298
+ /// Aborts iteration when a commit cannot be found
292
299
impl < ' commit > Iterator for ParentIds < ' commit > {
293
300
type Item = Oid ;
294
301
fn next ( & mut self ) -> Option < Oid > {
295
- self . range . next ( ) . map ( |i| self . commit . parent_id ( i) . unwrap ( ) )
302
+ self . range . next ( ) . and_then ( |i| self . commit . parent_id ( i) . ok ( ) )
296
303
}
297
304
fn size_hint ( & self ) -> ( usize , Option < usize > ) { self . range . size_hint ( ) }
298
305
}
299
306
307
+ /// Aborts iteration when a commit cannot be found
300
308
impl < ' commit > DoubleEndedIterator for ParentIds < ' commit > {
301
309
fn next_back ( & mut self ) -> Option < Oid > {
302
- self . range . next_back ( ) . map ( |i| self . commit . parent_id ( i) . unwrap ( ) )
310
+ self . range . next_back ( ) . and_then ( |i| self . commit . parent_id ( i) . ok ( ) )
303
311
}
304
312
}
305
313
0 commit comments