Skip to content

Implemented FusedIterator for various iterators #955

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
Aug 5, 2023
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: 3 additions & 0 deletions src/blame.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::util::{self, Binding};
use crate::{raw, signature, Oid, Repository, Signature};
use std::iter::FusedIterator;
use std::marker;
use std::mem;
use std::ops::Range;
Expand Down Expand Up @@ -307,6 +308,8 @@ impl<'blame> DoubleEndedIterator for BlameIter<'blame> {
}
}

impl<'blame> FusedIterator for BlameIter<'blame> {}

impl<'blame> ExactSizeIterator for BlameIter<'blame> {}

#[cfg(test)]
Expand Down
5 changes: 5 additions & 0 deletions src/commit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use libc;
use std::iter::FusedIterator;
use std::marker;
use std::mem;
use std::ops::Range;
Expand Down Expand Up @@ -376,6 +377,8 @@ impl<'repo, 'commit> DoubleEndedIterator for Parents<'commit, 'repo> {
}
}

impl<'repo, 'commit> FusedIterator for Parents<'commit, 'repo> {}

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

/// Aborts iteration when a commit cannot be found
Expand All @@ -400,6 +403,8 @@ impl<'commit> DoubleEndedIterator for ParentIds<'commit> {
}
}

impl<'commit> FusedIterator for ParentIds<'commit> {}

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

impl<'repo> Clone for Commit<'repo> {
Expand Down
3 changes: 3 additions & 0 deletions src/diff.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use libc::{c_char, c_int, c_void, size_t};
use std::ffi::CString;
use std::iter::FusedIterator;
use std::marker;
use std::mem;
use std::ops::Range;
Expand Down Expand Up @@ -959,6 +960,8 @@ impl<'diff> DoubleEndedIterator for Deltas<'diff> {
self.range.next_back().and_then(|i| self.diff.get_delta(i))
}
}
impl<'diff> FusedIterator for Deltas<'diff> {}

impl<'diff> ExactSizeIterator for Deltas<'diff> {}

/// Line origin constants.
Expand Down
5 changes: 5 additions & 0 deletions src/message.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::ops::Range;
use std::ffi::CStr;
use std::ffi::CString;
use std::iter::FusedIterator;
use std::ptr;

use libc::{c_char, c_int};
Expand Down Expand Up @@ -171,6 +172,8 @@ impl<'pair> Iterator for MessageTrailersStrsIterator<'pair> {
}
}

impl FusedIterator for MessageTrailersStrsIterator<'_> {}

impl ExactSizeIterator for MessageTrailersStrsIterator<'_> {
fn len(&self) -> usize {
self.0.range.len()
Expand Down Expand Up @@ -213,6 +216,8 @@ impl<'pair> Iterator for MessageTrailersBytesIterator<'pair> {
}
}

impl FusedIterator for MessageTrailersBytesIterator<'_> {}

impl ExactSizeIterator for MessageTrailersBytesIterator<'_> {
fn len(&self) -> usize {
self.0.range.len()
Expand Down
5 changes: 4 additions & 1 deletion src/pathspec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use libc::size_t;
use std::iter::IntoIterator;
use std::iter::{FusedIterator, IntoIterator};
use std::marker;
use std::ops::Range;
use std::path::Path;
Expand Down Expand Up @@ -297,6 +297,7 @@ impl<'list> DoubleEndedIterator for PathspecEntries<'list> {
self.range.next_back().and_then(|i| self.list.entry(i))
}
}
impl<'list> FusedIterator for PathspecEntries<'list> {}
impl<'list> ExactSizeIterator for PathspecEntries<'list> {}

impl<'list> Iterator for PathspecDiffEntries<'list> {
Expand All @@ -313,6 +314,7 @@ impl<'list> DoubleEndedIterator for PathspecDiffEntries<'list> {
self.range.next_back().and_then(|i| self.list.diff_entry(i))
}
}
impl<'list> FusedIterator for PathspecDiffEntries<'list> {}
impl<'list> ExactSizeIterator for PathspecDiffEntries<'list> {}

impl<'list> Iterator for PathspecFailedEntries<'list> {
Expand All @@ -331,6 +333,7 @@ impl<'list> DoubleEndedIterator for PathspecFailedEntries<'list> {
.and_then(|i| self.list.failed_entry(i))
}
}
impl<'list> FusedIterator for PathspecFailedEntries<'list> {}
impl<'list> ExactSizeIterator for PathspecFailedEntries<'list> {}

#[cfg(test)]
Expand Down
2 changes: 2 additions & 0 deletions src/reflog.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use libc::size_t;
use std::iter::FusedIterator;
use std::marker;
use std::ops::Range;
use std::str;
Expand Down Expand Up @@ -174,6 +175,7 @@ impl<'reflog> DoubleEndedIterator for ReflogIter<'reflog> {
self.range.next_back().and_then(|i| self.reflog.get(i))
}
}
impl<'reflog> FusedIterator for ReflogIter<'reflog> {}
impl<'reflog> ExactSizeIterator for ReflogIter<'reflog> {}

#[cfg(test)]
Expand Down
2 changes: 2 additions & 0 deletions src/remote.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use libc;
use raw::git_strarray;
use std::iter::FusedIterator;
use std::marker;
use std::mem;
use std::ops::Range;
Expand Down Expand Up @@ -462,6 +463,7 @@ impl<'repo> DoubleEndedIterator for Refspecs<'repo> {
.and_then(|i| self.remote.get_refspec(i))
}
}
impl<'repo> FusedIterator for Refspecs<'repo> {}
impl<'repo> ExactSizeIterator for Refspecs<'repo> {}

#[allow(missing_docs)] // not documented in libgit2 :(
Expand Down
2 changes: 2 additions & 0 deletions src/status.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use libc::{c_char, c_uint, size_t};
use std::ffi::CString;
use std::iter::FusedIterator;
use std::marker;
use std::mem;
use std::ops::Range;
Expand Down Expand Up @@ -303,6 +304,7 @@ impl<'a> DoubleEndedIterator for StatusIter<'a> {
self.range.next_back().and_then(|i| self.statuses.get(i))
}
}
impl<'a> FusedIterator for StatusIter<'a> {}
impl<'a> ExactSizeIterator for StatusIter<'a> {}

impl<'a> IntoIterator for &'a Statuses<'a> {
Expand Down
3 changes: 3 additions & 0 deletions src/string_array.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Bindings to libgit2's raw `git_strarray` type

use std::iter::FusedIterator;
use std::ops::Range;
use std::str;

Expand Down Expand Up @@ -108,6 +109,7 @@ impl<'a> DoubleEndedIterator for Iter<'a> {
self.range.next_back().map(|i| self.arr.get(i))
}
}
impl<'a> FusedIterator for Iter<'a> {}
impl<'a> ExactSizeIterator for Iter<'a> {}

impl<'a> Iterator for IterBytes<'a> {
Expand All @@ -124,6 +126,7 @@ impl<'a> DoubleEndedIterator for IterBytes<'a> {
self.range.next_back().and_then(|i| self.arr.get_bytes(i))
}
}
impl<'a> FusedIterator for IterBytes<'a> {}
impl<'a> ExactSizeIterator for IterBytes<'a> {}

impl Drop for StringArray {
Expand Down
2 changes: 2 additions & 0 deletions src/tree.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use libc::{self, c_char, c_int, c_void};
use std::cmp::Ordering;
use std::ffi::{CStr, CString};
use std::iter::FusedIterator;
use std::marker;
use std::mem;
use std::ops::Range;
Expand Down Expand Up @@ -401,6 +402,7 @@ impl<'tree> DoubleEndedIterator for TreeIter<'tree> {
self.range.next_back().and_then(|i| self.tree.get(i))
}
}
impl<'tree> FusedIterator for TreeIter<'tree> {}
impl<'tree> ExactSizeIterator for TreeIter<'tree> {}

#[cfg(test)]
Expand Down