Skip to content

Going with the new Iterators #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ impl<'repo> Branches<'repo> {
}
}

impl<'repo> Iterator<(Branch<'repo>, BranchType)> for Branches<'repo> {
impl<'repo> Iterator for Branches<'repo> {
type Item = (Branch<'repo>, BranchType);
fn next(&mut self) -> Option<(Branch<'repo>, BranchType)> {
let mut ret = 0 as *mut raw::git_reference;
let mut typ = raw::GIT_BRANCH_LOCAL;
Expand Down
14 changes: 8 additions & 6 deletions src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,35 +246,37 @@ impl<'repo> Commit<'repo> {
}
}

impl<'repo, 'commit> Iterator<Commit<'repo>> for Parents<'commit, 'repo> {
impl<'repo, 'commit> Iterator for Parents<'commit, 'repo> {
type Item = Commit<'repo>;
fn next(&mut self) -> Option<Commit<'repo>> {
self.range.next().map(|i| self.commit.parent(i).unwrap())
}
fn size_hint(&self) -> (uint, Option<uint>) { self.range.size_hint() }
}

impl<'repo, 'commit> DoubleEndedIterator<Commit<'repo>> for Parents<'commit, 'repo> {
impl<'repo, 'commit> DoubleEndedIterator for Parents<'commit, 'repo> {
fn next_back(&mut self) -> Option<Commit<'repo>> {
self.range.next_back().map(|i| self.commit.parent(i).unwrap())
}
}

impl<'repo, 'commit> ExactSizeIterator<Commit<'repo>> for Parents<'commit, 'repo> {}
impl<'repo, 'commit> ExactSizeIterator for Parents<'commit, 'repo> {}

impl<'commit> Iterator<Oid> for ParentIds<'commit> {
impl<'commit> Iterator for ParentIds<'commit> {
type Item = Oid;
fn next(&mut self) -> Option<Oid> {
self.range.next().map(|i| self.commit.parent_id(i).unwrap())
}
fn size_hint(&self) -> (uint, Option<uint>) { self.range.size_hint() }
}

impl<'commit> DoubleEndedIterator<Oid> for ParentIds<'commit> {
impl<'commit> DoubleEndedIterator for ParentIds<'commit> {
fn next_back(&mut self) -> Option<Oid> {
self.range.next_back().map(|i| self.commit.parent_id(i).unwrap())
}
}

impl<'commit> ExactSizeIterator<Oid> for ParentIds<'commit> {}
impl<'commit> ExactSizeIterator for ParentIds<'commit> {}

#[unsafe_destructor]
impl<'repo> Drop for Commit<'repo> {
Expand Down
3 changes: 2 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ impl<'cfg> ConfigEntries<'cfg> {
//
// It's also not implemented for `&'b mut T` so we can have multiple entries
// (ok).
impl<'cfg, 'b> Iterator<ConfigEntry<'b>> for &'b ConfigEntries<'cfg> {
impl<'cfg, 'b> Iterator for &'b ConfigEntries<'cfg> {
type Item = ConfigEntry<'b>;
fn next(&mut self) -> Option<ConfigEntry<'b>> {
let mut raw = 0 as *mut raw::git_config_entry;
unsafe {
Expand Down
7 changes: 4 additions & 3 deletions src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,18 +647,19 @@ impl DiffOptions {
// TODO: expose ignore_submodules, notify_cb/notify_payload
}

impl<'diff> Iterator<DiffDelta<'diff>> for Deltas<'diff> {
impl<'diff> Iterator for Deltas<'diff> {
type Item = DiffDelta<'diff>;
fn next(&mut self) -> Option<DiffDelta<'diff>> {
self.range.next().and_then(|i| self.diff.get_delta(i))
}
fn size_hint(&self) -> (uint, Option<uint>) { self.range.size_hint() }
}
impl<'diff> DoubleEndedIterator<DiffDelta<'diff>> for Deltas<'diff> {
impl<'diff> DoubleEndedIterator for Deltas<'diff> {
fn next_back(&mut self) -> Option<DiffDelta<'diff>> {
self.range.next_back().and_then(|i| self.diff.get_delta(i))
}
}
impl<'diff> ExactSizeIterator<DiffDelta<'diff>> for Deltas<'diff> {}
impl<'diff> ExactSizeIterator for Deltas<'diff> {}

impl<'a> DiffLine<'a> {
/// Create a new diff line from its raw component.
Expand Down
3 changes: 2 additions & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ impl Drop for Index {
}
}

impl<'index> Iterator<IndexEntry> for IndexEntries<'index> {
impl<'index> Iterator for IndexEntries<'index> {
type Item = IndexEntry;
fn next(&mut self) -> Option<IndexEntry> {
self.range.next().map(|i| self.index.get(i).unwrap())
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
//! itself.

#![feature(macro_rules, unsafe_destructor, unboxed_closures)]
#![feature(associated_types)]
#![deny(missing_docs)]
#![cfg_attr(test, deny(warnings))]

Expand Down
3 changes: 2 additions & 1 deletion src/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ impl<'repo> Notes<'repo> {
}
}

impl<'repo> Iterator<(Oid, Oid)> for Notes<'repo> {
impl<'repo> Iterator for Notes<'repo> {
type Item = (Oid, Oid);
fn next(&mut self) -> Option<(Oid, Oid)> {
let mut note_id = raw::git_oid { id: [0; raw::GIT_OID_RAWSZ] };
let mut annotated_id = note_id;
Expand Down
23 changes: 13 additions & 10 deletions src/pathspec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct PathspecFailedEntries<'list> {
impl Pathspec {
/// Creates a new pathspec from a list of specs to match against.
pub fn new<I, T>(specs: I) -> Result<Pathspec, Error>
where T: ToCStr, I: Iterator<T> {
where T: ToCStr, I: Iterator<Item=T> {
let strs = specs.map(|s| s.to_c_str()).collect::<Vec<_>>();
let ptrs = strs.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();
let arr = raw::git_strarray {
Expand Down Expand Up @@ -222,44 +222,47 @@ impl<'ps> Drop for PathspecMatchList<'ps> {
}
}

impl<'list> Iterator<&'list [u8]> for PathspecEntries<'list> {
impl<'list> Iterator for PathspecEntries<'list> {
type Item = &'list [u8];
fn next(&mut self) -> Option<&'list [u8]> {
self.range.next().and_then(|i| self.list.entry(i))
}
fn size_hint(&self) -> (uint, Option<uint>) { self.range.size_hint() }
}
impl<'list> DoubleEndedIterator<&'list [u8]> for PathspecEntries<'list> {
impl<'list> DoubleEndedIterator for PathspecEntries<'list> {
fn next_back(&mut self) -> Option<&'list [u8]> {
self.range.next_back().and_then(|i| self.list.entry(i))
}
}
impl<'list> ExactSizeIterator<&'list [u8]> for PathspecEntries<'list> {}
impl<'list> ExactSizeIterator for PathspecEntries<'list> {}

impl<'list> Iterator<DiffDelta<'list>> for PathspecDiffEntries<'list> {
impl<'list> Iterator for PathspecDiffEntries<'list> {
type Item = DiffDelta<'list>;
fn next(&mut self) -> Option<DiffDelta<'list>> {
self.range.next().and_then(|i| self.list.diff_entry(i))
}
fn size_hint(&self) -> (uint, Option<uint>) { self.range.size_hint() }
}
impl<'list> DoubleEndedIterator<DiffDelta<'list>> for PathspecDiffEntries<'list> {
impl<'list> DoubleEndedIterator for PathspecDiffEntries<'list> {
fn next_back(&mut self) -> Option<DiffDelta<'list>> {
self.range.next_back().and_then(|i| self.list.diff_entry(i))
}
}
impl<'list> ExactSizeIterator<DiffDelta<'list>> for PathspecDiffEntries<'list> {}
impl<'list> ExactSizeIterator for PathspecDiffEntries<'list> {}

impl<'list> Iterator<&'list [u8]> for PathspecFailedEntries<'list> {
impl<'list> Iterator for PathspecFailedEntries<'list> {
type Item = &'list [u8];
fn next(&mut self) -> Option<&'list [u8]> {
self.range.next().and_then(|i| self.list.failed_entry(i))
}
fn size_hint(&self) -> (uint, Option<uint>) { self.range.size_hint() }
}
impl<'list> DoubleEndedIterator<&'list [u8]> for PathspecFailedEntries<'list> {
impl<'list> DoubleEndedIterator for PathspecFailedEntries<'list> {
fn next_back(&mut self) -> Option<&'list [u8]> {
self.range.next_back().and_then(|i| self.list.failed_entry(i))
}
}
impl<'list> ExactSizeIterator<&'list [u8]> for PathspecFailedEntries<'list> {}
impl<'list> ExactSizeIterator for PathspecFailedEntries<'list> {}

#[cfg(test)]
mod tests {
Expand Down
6 changes: 4 additions & 2 deletions src/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ impl<'repo> References<'repo> {
}
}

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

impl<'repo> Iterator<&'repo str> for ReferenceNames<'repo> {
impl<'repo> Iterator for ReferenceNames<'repo> {
type Item = &'repo str;
fn next(&mut self) -> Option<&'repo str> {
let mut out = 0 as *const libc::c_char;
if unsafe { raw::git_reference_next_name(&mut out, self.inner.raw) == 0 } {
Expand Down
11 changes: 6 additions & 5 deletions src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ impl<'repo, 'cb> Remote<'repo, 'cb> {
}

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

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

impl<'a, 'b> Iterator<Refspec<'a>> for Refspecs<'a, 'b> {
impl<'a, 'b> Iterator for Refspecs<'a, 'b> {
type Item = Refspec<'a>;
fn next(&mut self) -> Option<Refspec<'a>> {
if self.cur == self.cnt { return None }
let ret = unsafe {
Expand Down
6 changes: 3 additions & 3 deletions src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ impl Repository {
/// matching the provided pathspecs.
pub fn reset_default<'a,
T: ToCStr,
I: Iterator<T>>(&'a self,
target: Option<&Object<'a>>,
paths: I) -> Result<(), Error> {
I: Iterator<Item=T>>(&'a self,
target: Option<&Object<'a>>,
paths: I) -> Result<(), Error> {
let v = paths.map(|t| t.to_c_str()).collect::<Vec<CString>>();
let v2 = v.iter().map(|v| v.as_ptr()).collect::<Vec<*const c_char>>();
let mut arr = raw::git_strarray {
Expand Down
3 changes: 2 additions & 1 deletion src/revwalk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ impl<'repo> Drop for Revwalk<'repo> {
}
}

impl<'repo> Iterator<Oid> for Revwalk<'repo> {
impl<'repo> Iterator for Revwalk<'repo> {
type Item = Oid;
fn next(&mut self) -> Option<Oid> {
let mut out: raw::git_oid = raw::git_oid{ id: [0; raw::GIT_OID_RAWSZ] };
unsafe {
Expand Down
7 changes: 4 additions & 3 deletions src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,20 +279,21 @@ impl<'repo> Drop for Statuses<'repo> {
}
}

impl<'a> Iterator<StatusEntry<'a>> for StatusIter<'a> {
impl<'a> Iterator for StatusIter<'a> {
type Item = StatusEntry<'a>;
fn next(&mut self) -> Option<StatusEntry<'a>> {
self.range.next().and_then(|i| self.statuses.get(i))
}
fn size_hint(&self) -> (uint, Option<uint>) { self.range.size_hint() }
}

impl<'a> DoubleEndedIterator<StatusEntry<'a>> for StatusIter<'a> {
impl<'a> DoubleEndedIterator for StatusIter<'a> {
fn next_back(&mut self) -> Option<StatusEntry<'a>> {
self.range.next_back().and_then(|i| self.statuses.get(i))
}
}

impl<'a> ExactSizeIterator<StatusEntry<'a>> for StatusIter<'a> {}
impl<'a> ExactSizeIterator for StatusIter<'a> {}

impl<'statuses> StatusEntry<'statuses> {
/// Create a new status entry from its raw component.
Expand Down
6 changes: 4 additions & 2 deletions src/string_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ impl StringArray {
pub fn len(&self) -> uint { self.raw.count as uint }
}

impl<'a> Iterator<Option<&'a str>> for StringArrayItems<'a> {
impl<'a> Iterator for StringArrayItems<'a> {
type Item = Option<&'a str>;
fn next(&mut self) -> Option<Option<&'a str>> {
if self.cur < self.arr.len() {
self.cur += 1;
Expand All @@ -79,7 +80,8 @@ impl<'a> Iterator<Option<&'a str>> for StringArrayItems<'a> {
}
}

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