Skip to content

Commit 197e1c1

Browse files
committed
Merge pull request #36 from akiss77/pr-iter
Going with the new `Iterator`s
2 parents 6760bef + cc5fa9b commit 197e1c1

File tree

14 files changed

+57
-39
lines changed

14 files changed

+57
-39
lines changed

src/branch.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ impl<'repo> Branches<'repo> {
113113
}
114114
}
115115

116-
impl<'repo> Iterator<(Branch<'repo>, BranchType)> for Branches<'repo> {
116+
impl<'repo> Iterator for Branches<'repo> {
117+
type Item = (Branch<'repo>, BranchType);
117118
fn next(&mut self) -> Option<(Branch<'repo>, BranchType)> {
118119
let mut ret = 0 as *mut raw::git_reference;
119120
let mut typ = raw::GIT_BRANCH_LOCAL;

src/commit.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,35 +246,37 @@ impl<'repo> Commit<'repo> {
246246
}
247247
}
248248

249-
impl<'repo, 'commit> Iterator<Commit<'repo>> for Parents<'commit, 'repo> {
249+
impl<'repo, 'commit> Iterator for Parents<'commit, 'repo> {
250+
type Item = Commit<'repo>;
250251
fn next(&mut self) -> Option<Commit<'repo>> {
251252
self.range.next().map(|i| self.commit.parent(i).unwrap())
252253
}
253254
fn size_hint(&self) -> (uint, Option<uint>) { self.range.size_hint() }
254255
}
255256

256-
impl<'repo, 'commit> DoubleEndedIterator<Commit<'repo>> for Parents<'commit, 'repo> {
257+
impl<'repo, 'commit> DoubleEndedIterator for Parents<'commit, 'repo> {
257258
fn next_back(&mut self) -> Option<Commit<'repo>> {
258259
self.range.next_back().map(|i| self.commit.parent(i).unwrap())
259260
}
260261
}
261262

262-
impl<'repo, 'commit> ExactSizeIterator<Commit<'repo>> for Parents<'commit, 'repo> {}
263+
impl<'repo, 'commit> ExactSizeIterator for Parents<'commit, 'repo> {}
263264

264-
impl<'commit> Iterator<Oid> for ParentIds<'commit> {
265+
impl<'commit> Iterator for ParentIds<'commit> {
266+
type Item = Oid;
265267
fn next(&mut self) -> Option<Oid> {
266268
self.range.next().map(|i| self.commit.parent_id(i).unwrap())
267269
}
268270
fn size_hint(&self) -> (uint, Option<uint>) { self.range.size_hint() }
269271
}
270272

271-
impl<'commit> DoubleEndedIterator<Oid> for ParentIds<'commit> {
273+
impl<'commit> DoubleEndedIterator for ParentIds<'commit> {
272274
fn next_back(&mut self) -> Option<Oid> {
273275
self.range.next_back().map(|i| self.commit.parent_id(i).unwrap())
274276
}
275277
}
276278

277-
impl<'commit> ExactSizeIterator<Oid> for ParentIds<'commit> {}
279+
impl<'commit> ExactSizeIterator for ParentIds<'commit> {}
278280

279281
#[unsafe_destructor]
280282
impl<'repo> Drop for Commit<'repo> {

src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ impl<'cfg> ConfigEntries<'cfg> {
386386
//
387387
// It's also not implemented for `&'b mut T` so we can have multiple entries
388388
// (ok).
389-
impl<'cfg, 'b> Iterator<ConfigEntry<'b>> for &'b ConfigEntries<'cfg> {
389+
impl<'cfg, 'b> Iterator for &'b ConfigEntries<'cfg> {
390+
type Item = ConfigEntry<'b>;
390391
fn next(&mut self) -> Option<ConfigEntry<'b>> {
391392
let mut raw = 0 as *mut raw::git_config_entry;
392393
unsafe {

src/diff.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,18 +647,19 @@ impl DiffOptions {
647647
// TODO: expose ignore_submodules, notify_cb/notify_payload
648648
}
649649

650-
impl<'diff> Iterator<DiffDelta<'diff>> for Deltas<'diff> {
650+
impl<'diff> Iterator for Deltas<'diff> {
651+
type Item = DiffDelta<'diff>;
651652
fn next(&mut self) -> Option<DiffDelta<'diff>> {
652653
self.range.next().and_then(|i| self.diff.get_delta(i))
653654
}
654655
fn size_hint(&self) -> (uint, Option<uint>) { self.range.size_hint() }
655656
}
656-
impl<'diff> DoubleEndedIterator<DiffDelta<'diff>> for Deltas<'diff> {
657+
impl<'diff> DoubleEndedIterator for Deltas<'diff> {
657658
fn next_back(&mut self) -> Option<DiffDelta<'diff>> {
658659
self.range.next_back().and_then(|i| self.diff.get_delta(i))
659660
}
660661
}
661-
impl<'diff> ExactSizeIterator<DiffDelta<'diff>> for Deltas<'diff> {}
662+
impl<'diff> ExactSizeIterator for Deltas<'diff> {}
662663

663664
impl<'a> DiffLine<'a> {
664665
/// Create a new diff line from its raw component.

src/index.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,8 @@ impl Drop for Index {
420420
}
421421
}
422422

423-
impl<'index> Iterator<IndexEntry> for IndexEntries<'index> {
423+
impl<'index> Iterator for IndexEntries<'index> {
424+
type Item = IndexEntry;
424425
fn next(&mut self) -> Option<IndexEntry> {
425426
self.range.next().map(|i| self.index.get(i).unwrap())
426427
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
//! itself.
6565
6666
#![feature(macro_rules, unsafe_destructor, unboxed_closures)]
67+
#![feature(associated_types)]
6768
#![deny(missing_docs)]
6869
#![cfg_attr(test, deny(warnings))]
6970

src/note.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ impl<'repo> Notes<'repo> {
7979
}
8080
}
8181

82-
impl<'repo> Iterator<(Oid, Oid)> for Notes<'repo> {
82+
impl<'repo> Iterator for Notes<'repo> {
83+
type Item = (Oid, Oid);
8384
fn next(&mut self) -> Option<(Oid, Oid)> {
8485
let mut note_id = raw::git_oid { id: [0; raw::GIT_OID_RAWSZ] };
8586
let mut annotated_id = note_id;

src/pathspec.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub struct PathspecFailedEntries<'list> {
3838
impl Pathspec {
3939
/// Creates a new pathspec from a list of specs to match against.
4040
pub fn new<I, T>(specs: I) -> Result<Pathspec, Error>
41-
where T: ToCStr, I: Iterator<T> {
41+
where T: ToCStr, I: Iterator<Item=T> {
4242
let strs = specs.map(|s| s.to_c_str()).collect::<Vec<_>>();
4343
let ptrs = strs.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();
4444
let arr = raw::git_strarray {
@@ -222,44 +222,47 @@ impl<'ps> Drop for PathspecMatchList<'ps> {
222222
}
223223
}
224224

225-
impl<'list> Iterator<&'list [u8]> for PathspecEntries<'list> {
225+
impl<'list> Iterator for PathspecEntries<'list> {
226+
type Item = &'list [u8];
226227
fn next(&mut self) -> Option<&'list [u8]> {
227228
self.range.next().and_then(|i| self.list.entry(i))
228229
}
229230
fn size_hint(&self) -> (uint, Option<uint>) { self.range.size_hint() }
230231
}
231-
impl<'list> DoubleEndedIterator<&'list [u8]> for PathspecEntries<'list> {
232+
impl<'list> DoubleEndedIterator for PathspecEntries<'list> {
232233
fn next_back(&mut self) -> Option<&'list [u8]> {
233234
self.range.next_back().and_then(|i| self.list.entry(i))
234235
}
235236
}
236-
impl<'list> ExactSizeIterator<&'list [u8]> for PathspecEntries<'list> {}
237+
impl<'list> ExactSizeIterator for PathspecEntries<'list> {}
237238

238-
impl<'list> Iterator<DiffDelta<'list>> for PathspecDiffEntries<'list> {
239+
impl<'list> Iterator for PathspecDiffEntries<'list> {
240+
type Item = DiffDelta<'list>;
239241
fn next(&mut self) -> Option<DiffDelta<'list>> {
240242
self.range.next().and_then(|i| self.list.diff_entry(i))
241243
}
242244
fn size_hint(&self) -> (uint, Option<uint>) { self.range.size_hint() }
243245
}
244-
impl<'list> DoubleEndedIterator<DiffDelta<'list>> for PathspecDiffEntries<'list> {
246+
impl<'list> DoubleEndedIterator for PathspecDiffEntries<'list> {
245247
fn next_back(&mut self) -> Option<DiffDelta<'list>> {
246248
self.range.next_back().and_then(|i| self.list.diff_entry(i))
247249
}
248250
}
249-
impl<'list> ExactSizeIterator<DiffDelta<'list>> for PathspecDiffEntries<'list> {}
251+
impl<'list> ExactSizeIterator for PathspecDiffEntries<'list> {}
250252

251-
impl<'list> Iterator<&'list [u8]> for PathspecFailedEntries<'list> {
253+
impl<'list> Iterator for PathspecFailedEntries<'list> {
254+
type Item = &'list [u8];
252255
fn next(&mut self) -> Option<&'list [u8]> {
253256
self.range.next().and_then(|i| self.list.failed_entry(i))
254257
}
255258
fn size_hint(&self) -> (uint, Option<uint>) { self.range.size_hint() }
256259
}
257-
impl<'list> DoubleEndedIterator<&'list [u8]> for PathspecFailedEntries<'list> {
260+
impl<'list> DoubleEndedIterator for PathspecFailedEntries<'list> {
258261
fn next_back(&mut self) -> Option<&'list [u8]> {
259262
self.range.next_back().and_then(|i| self.list.failed_entry(i))
260263
}
261264
}
262-
impl<'list> ExactSizeIterator<&'list [u8]> for PathspecFailedEntries<'list> {}
265+
impl<'list> ExactSizeIterator for PathspecFailedEntries<'list> {}
263266

264267
#[cfg(test)]
265268
mod tests {

src/reference.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ impl<'repo> References<'repo> {
226226
}
227227
}
228228

229-
impl<'repo> Iterator<Reference<'repo>> for References<'repo> {
229+
impl<'repo> Iterator for References<'repo> {
230+
type Item = Reference<'repo>;
230231
fn next(&mut self) -> Option<Reference<'repo>> {
231232
let mut out = 0 as *mut raw::git_reference;
232233
if unsafe { raw::git_reference_next(&mut out, self.raw) == 0 } {
@@ -257,7 +258,8 @@ impl<'repo> ReferenceNames<'repo> {
257258
}
258259
}
259260

260-
impl<'repo> Iterator<&'repo str> for ReferenceNames<'repo> {
261+
impl<'repo> Iterator for ReferenceNames<'repo> {
262+
type Item = &'repo str;
261263
fn next(&mut self) -> Option<&'repo str> {
262264
let mut out = 0 as *const libc::c_char;
263265
if unsafe { raw::git_reference_next_name(&mut out, self.inner.raw) == 0 } {

src/remote.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ impl<'repo, 'cb> Remote<'repo, 'cb> {
168168
}
169169

170170
/// Set the remote's list of fetch refspecs
171-
pub fn set_fetch_refspecs<T: ToCStr, I: Iterator<T>>(&mut self, i: I)
172-
-> Result<(), Error> {
171+
pub fn set_fetch_refspecs<T: ToCStr, I: Iterator<Item=T>>(&mut self, i: I)
172+
-> Result<(), Error> {
173173
let v = i.map(|t| t.to_c_str()).collect::<Vec<CString>>();
174174
let v2 = v.iter().map(|v| v.as_ptr()).collect::<Vec<*const libc::c_char>>();
175175
let mut arr = raw::git_strarray {
@@ -184,8 +184,8 @@ impl<'repo, 'cb> Remote<'repo, 'cb> {
184184
}
185185

186186
/// Set the remote's list of push refspecs
187-
pub fn set_push_refspecs<T: ToCStr, I: Iterator<T>>(&mut self, i: I)
188-
-> Result<(), Error> {
187+
pub fn set_push_refspecs<T: ToCStr, I: Iterator<Item=T>>(&mut self, i: I)
188+
-> Result<(), Error> {
189189
let v = i.map(|t| t.to_c_str()).collect::<Vec<CString>>();
190190
let v2 = v.iter().map(|v| v.as_ptr()).collect::<Vec<*const libc::c_char>>();
191191
let mut arr = raw::git_strarray {
@@ -329,7 +329,8 @@ impl<'repo, 'cb> Remote<'repo, 'cb> {
329329
}
330330
}
331331

332-
impl<'a, 'b> Iterator<Refspec<'a>> for Refspecs<'a, 'b> {
332+
impl<'a, 'b> Iterator for Refspecs<'a, 'b> {
333+
type Item = Refspec<'a>;
333334
fn next(&mut self) -> Option<Refspec<'a>> {
334335
if self.cur == self.cnt { return None }
335336
let ret = unsafe {

src/repo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ impl Repository {
359359
/// matching the provided pathspecs.
360360
pub fn reset_default<'a,
361361
T: ToCStr,
362-
I: Iterator<T>>(&'a self,
363-
target: Option<&Object<'a>>,
364-
paths: I) -> Result<(), Error> {
362+
I: Iterator<Item=T>>(&'a self,
363+
target: Option<&Object<'a>>,
364+
paths: I) -> Result<(), Error> {
365365
let v = paths.map(|t| t.to_c_str()).collect::<Vec<CString>>();
366366
let v2 = v.iter().map(|v| v.as_ptr()).collect::<Vec<*const c_char>>();
367367
let mut arr = raw::git_strarray {

src/revwalk.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ impl<'repo> Drop for Revwalk<'repo> {
160160
}
161161
}
162162

163-
impl<'repo> Iterator<Oid> for Revwalk<'repo> {
163+
impl<'repo> Iterator for Revwalk<'repo> {
164+
type Item = Oid;
164165
fn next(&mut self) -> Option<Oid> {
165166
let mut out: raw::git_oid = raw::git_oid{ id: [0; raw::GIT_OID_RAWSZ] };
166167
unsafe {

src/status.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,20 +279,21 @@ impl<'repo> Drop for Statuses<'repo> {
279279
}
280280
}
281281

282-
impl<'a> Iterator<StatusEntry<'a>> for StatusIter<'a> {
282+
impl<'a> Iterator for StatusIter<'a> {
283+
type Item = StatusEntry<'a>;
283284
fn next(&mut self) -> Option<StatusEntry<'a>> {
284285
self.range.next().and_then(|i| self.statuses.get(i))
285286
}
286287
fn size_hint(&self) -> (uint, Option<uint>) { self.range.size_hint() }
287288
}
288289

289-
impl<'a> DoubleEndedIterator<StatusEntry<'a>> for StatusIter<'a> {
290+
impl<'a> DoubleEndedIterator for StatusIter<'a> {
290291
fn next_back(&mut self) -> Option<StatusEntry<'a>> {
291292
self.range.next_back().and_then(|i| self.statuses.get(i))
292293
}
293294
}
294295

295-
impl<'a> ExactSizeIterator<StatusEntry<'a>> for StatusIter<'a> {}
296+
impl<'a> ExactSizeIterator for StatusIter<'a> {}
296297

297298
impl<'statuses> StatusEntry<'statuses> {
298299
/// Create a new status entry from its raw component.

src/string_array.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ impl StringArray {
6868
pub fn len(&self) -> uint { self.raw.count as uint }
6969
}
7070

71-
impl<'a> Iterator<Option<&'a str>> for StringArrayItems<'a> {
71+
impl<'a> Iterator for StringArrayItems<'a> {
72+
type Item = Option<&'a str>;
7273
fn next(&mut self) -> Option<Option<&'a str>> {
7374
if self.cur < self.arr.len() {
7475
self.cur += 1;
@@ -79,7 +80,8 @@ impl<'a> Iterator<Option<&'a str>> for StringArrayItems<'a> {
7980
}
8081
}
8182

82-
impl<'a> Iterator<&'a [u8]> for StringArrayBytes<'a> {
83+
impl<'a> Iterator for StringArrayBytes<'a> {
84+
type Item = &'a [u8];
8385
fn next(&mut self) -> Option<&'a [u8]> {
8486
if self.cur < self.arr.len() {
8587
self.cur += 1;

0 commit comments

Comments
 (0)