@@ -6,8 +6,8 @@ use std::{
66} ;
77
88use crate :: {
9- file:: { self , File , EXTENDED_EDGES_MASK , LAST_EXTENDED_EDGE_MASK , NO_PARENT } ,
10- graph ,
9+ file:: { self , EXTENDED_EDGES_MASK , LAST_EXTENDED_EDGE_MASK , NO_PARENT } ,
10+ File , Position ,
1111} ;
1212
1313/// The error used in the [`file::commit`][self] module.
@@ -25,6 +25,7 @@ pub enum Error {
2525}
2626
2727/// A commit as stored in a [`File`].
28+ #[ derive( Copy , Clone ) ]
2829pub struct Commit < ' a > {
2930 file : & ' a File ,
3031 pos : file:: Position ,
@@ -72,11 +73,11 @@ impl<'a> Commit<'a> {
7273 }
7374
7475 /// Returns an iterator over the parent positions for lookup in the owning [Graph][crate::Graph].
75- pub fn iter_parents ( & ' a self ) -> impl Iterator < Item = Result < graph :: Position , Error > > + ' a {
76+ pub fn iter_parents ( self ) -> Parents < ' a > {
7677 // I didn't find a combinator approach that a) was as strict as ParentIterator, b) supported
7778 // fuse-after-first-error behavior, and b) was significantly shorter or more understandable
7879 // than ParentIterator. So here we are.
79- ParentIterator {
80+ Parents {
8081 commit_data : self ,
8182 state : ParentIteratorState :: First ,
8283 }
@@ -88,7 +89,7 @@ impl<'a> Commit<'a> {
8889 }
8990
9091 /// Returns the first parent of this commit.
91- pub fn parent1 ( & self ) -> Result < Option < graph :: Position > , Error > {
92+ pub fn parent1 ( & self ) -> Result < Option < Position > , Error > {
9293 self . iter_parents ( ) . next ( ) . transpose ( )
9394 }
9495
@@ -127,13 +128,13 @@ impl<'a> PartialEq for Commit<'a> {
127128}
128129
129130/// An iterator over parents of a [`Commit`].
130- pub struct ParentIterator < ' a > {
131- commit_data : & ' a Commit < ' a > ,
131+ pub struct Parents < ' a > {
132+ commit_data : Commit < ' a > ,
132133 state : ParentIteratorState < ' a > ,
133134}
134135
135- impl < ' a > Iterator for ParentIterator < ' a > {
136- type Item = Result < graph :: Position , Error > ;
136+ impl < ' a > Iterator for Parents < ' a > {
137+ type Item = Result < Position , Error > ;
137138
138139 fn next ( & mut self ) -> Option < Self :: Item > {
139140 let state = std:: mem:: replace ( & mut self . state , ParentIteratorState :: Exhausted ) ;
@@ -221,7 +222,7 @@ enum ParentIteratorState<'a> {
221222#[ derive( Clone , Copy , Debug ) ]
222223enum ParentEdge {
223224 None ,
224- GraphPosition ( graph :: Position ) ,
225+ GraphPosition ( Position ) ,
225226 ExtraEdgeIndex ( u32 ) ,
226227}
227228
@@ -233,22 +234,22 @@ impl ParentEdge {
233234 if raw & EXTENDED_EDGES_MASK != 0 {
234235 ParentEdge :: ExtraEdgeIndex ( raw & !EXTENDED_EDGES_MASK )
235236 } else {
236- ParentEdge :: GraphPosition ( graph :: Position ( raw) )
237+ ParentEdge :: GraphPosition ( Position ( raw) )
237238 }
238239 }
239240}
240241
241242enum ExtraEdge {
242- Internal ( graph :: Position ) ,
243- Last ( graph :: Position ) ,
243+ Internal ( Position ) ,
244+ Last ( Position ) ,
244245}
245246
246247impl ExtraEdge {
247248 pub fn from_raw ( raw : u32 ) -> Self {
248249 if raw & LAST_EXTENDED_EDGE_MASK != 0 {
249- Self :: Last ( graph :: Position ( raw & !LAST_EXTENDED_EDGE_MASK ) )
250+ Self :: Last ( Position ( raw & !LAST_EXTENDED_EDGE_MASK ) )
250251 } else {
251- Self :: Internal ( graph :: Position ( raw) )
252+ Self :: Internal ( Position ( raw) )
252253 }
253254 }
254255}
0 commit comments