Skip to content
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

Clippy style #839

Merged
merged 2 commits into from Jan 10, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion benches/extra/zipslices.rs
Expand Up @@ -58,7 +58,7 @@ where
#[inline(always)]
pub fn from_slices(a: T, b: U) -> Self {
let minl = cmp::min(a.len(), b.len());
ZipSlices {
Self {
t: a,
u: b,
len: minl,
Expand Down
4 changes: 2 additions & 2 deletions examples/iris.rs
Expand Up @@ -25,7 +25,7 @@ enum ParseError {

impl From<ParseFloatError> for ParseError {
fn from(err: ParseFloatError) -> Self {
ParseError::Numeric(err)
Self::Numeric(err)
}
}

Expand All @@ -34,7 +34,7 @@ impl FromStr for Iris {
type Err = ParseError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut iris = Iris {
let mut iris = Self {
name: "".into(),
data: [0.; 4],
};
Expand Down
5 changes: 3 additions & 2 deletions src/adaptors/coalesce.rs
Expand Up @@ -17,9 +17,10 @@ where
f: F,
}

impl<I: Clone, F: Clone, C> Clone for CoalesceBy<I, F, C>
impl<I, F, C> Clone for CoalesceBy<I, F, C>
where
I: Iterator,
I: Clone + Iterator,
F: Clone,
C: CountItem<I::Item>,
C::CItem: Clone,
{
Expand Down
4 changes: 2 additions & 2 deletions src/adaptors/mod.rs
Expand Up @@ -218,7 +218,7 @@ where
/// Split the `PutBack` into its parts.
#[inline]
pub fn into_parts(self) -> (Option<I::Item>, I) {
let PutBack { top, iter } = self;
let Self { top, iter } = self;
(top, iter)
}

Expand Down Expand Up @@ -689,7 +689,7 @@ pub struct Tuple1Combination<I> {

impl<I> From<I> for Tuple1Combination<I> {
fn from(iter: I) -> Self {
Tuple1Combination { iter }
Self { iter }
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/adaptors/multi_product.rs
Expand Up @@ -95,7 +95,7 @@ where

if last.in_progress() {
true
} else if MultiProduct::iterate_last(rest, state) {
} else if Self::iterate_last(rest, state) {
last.reset();
last.iterate();
// If iterator is None twice consecutively, then iterator is
Expand Down Expand Up @@ -139,7 +139,7 @@ where
I::Item: Clone,
{
fn new(iter: I) -> Self {
MultiProductIter {
Self {
cur: None,
iter: iter.clone(),
iter_orig: iter,
Expand Down Expand Up @@ -171,7 +171,7 @@ where
type Item = Vec<I::Item>;

fn next(&mut self) -> Option<Self::Item> {
if MultiProduct::iterate_last(&mut self.0, MultiProductIterState::StartOfIter) {
if Self::iterate_last(&mut self.0, MultiProductIterState::StartOfIter) {
Some(self.curr_iterator())
} else {
None
Expand Down
6 changes: 3 additions & 3 deletions src/duplicates_impl.rs
Expand Up @@ -22,7 +22,7 @@ mod private {

impl<I: Iterator, Key: Eq + Hash, F> DuplicatesBy<I, Key, F> {
pub(crate) fn new(iter: I, key_method: F) -> Self {
DuplicatesBy {
Self {
iter,
meta: Meta {
used: HashMap::new(),
Expand Down Expand Up @@ -77,7 +77,7 @@ mod private {
type Item = I::Item;

fn next(&mut self) -> Option<Self::Item> {
let DuplicatesBy { iter, meta } = self;
let Self { iter, meta } = self;
iter.find_map(|v| meta.filter(v))
}

Expand Down Expand Up @@ -109,7 +109,7 @@ mod private {
F: KeyMethod<Key, I::Item>,
{
fn next_back(&mut self) -> Option<Self::Item> {
let DuplicatesBy { iter, meta } = self;
let Self { iter, meta } = self;
iter.rev().find_map(|v| meta.filter(v))
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/either_or_both.rs
Expand Up @@ -301,9 +301,9 @@ impl<A, B> EitherOrBoth<A, B> {
B: Default,
{
match self {
EitherOrBoth::Left(l) => (l, B::default()),
EitherOrBoth::Right(r) => (A::default(), r),
EitherOrBoth::Both(l, r) => (l, r),
Left(l) => (l, B::default()),
Right(r) => (A::default(), r),
Both(l, r) => (l, r),
}
}

Expand Down Expand Up @@ -498,18 +498,18 @@ impl<T> EitherOrBoth<T, T> {
impl<A, B> Into<Option<Either<A, B>>> for EitherOrBoth<A, B> {
fn into(self) -> Option<Either<A, B>> {
match self {
EitherOrBoth::Left(l) => Some(Either::Left(l)),
EitherOrBoth::Right(r) => Some(Either::Right(r)),
_ => None,
Left(l) => Some(Either::Left(l)),
Right(r) => Some(Either::Right(r)),
Both(..) => None,
}
}
}

impl<A, B> From<Either<A, B>> for EitherOrBoth<A, B> {
fn from(either: Either<A, B>) -> Self {
match either {
Either::Left(l) => EitherOrBoth::Left(l),
Either::Right(l) => EitherOrBoth::Right(l),
Either::Left(l) => Left(l),
Either::Right(l) => Right(l),
}
}
}
4 changes: 2 additions & 2 deletions src/free.rs
Expand Up @@ -166,10 +166,10 @@ where
///
/// assert_eq!(cloned(b"abc").next(), Some(b'a'));
/// ```
pub fn cloned<'a, I, T: 'a>(iterable: I) -> iter::Cloned<I::IntoIter>
pub fn cloned<'a, I, T>(iterable: I) -> iter::Cloned<I::IntoIter>
where
I: IntoIterator<Item = &'a T>,
T: Clone,
T: Clone + 'a,
{
iterable.into_iter().cloned()
}
Expand Down
26 changes: 15 additions & 11 deletions src/groupbylazy.rs
Expand Up @@ -7,9 +7,9 @@ trait KeyFunction<A> {
fn call_mut(&mut self, arg: A) -> Self::Key;
}

impl<A, K, F: ?Sized> KeyFunction<A> for F
impl<A, K, F> KeyFunction<A> for F
where
F: FnMut(A) -> K,
F: FnMut(A) -> K + ?Sized,
{
type Key = K;
#[inline]
Expand All @@ -29,7 +29,7 @@ struct ChunkIndex {
impl ChunkIndex {
#[inline(always)]
fn new(size: usize) -> Self {
ChunkIndex {
Self {
size,
index: 0,
key: 0,
Expand Down Expand Up @@ -370,10 +370,12 @@ where
///
/// See [`.group_by()`](crate::Itertools::group_by) for more information.
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
pub struct Groups<'a, K: 'a, I: 'a, F: 'a>
pub struct Groups<'a, K, I, F>
where
I: Iterator,
I: Iterator + 'a,
I::Item: 'a,
K: 'a,
F: 'a,
{
parent: &'a GroupBy<K, I, F>,
}
Expand Down Expand Up @@ -409,10 +411,12 @@ where
/// An iterator for the elements in a single group.
///
/// Iterator element type is `I::Item`.
pub struct Group<'a, K: 'a, I: 'a, F: 'a>
pub struct Group<'a, K, I, F>
where
I: Iterator,
I: Iterator + 'a,
I::Item: 'a,
K: 'a,
F: 'a,
{
parent: &'a GroupBy<K, I, F>,
index: usize,
Expand Down Expand Up @@ -537,9 +541,9 @@ where
/// See [`.chunks()`](crate::Itertools::chunks) for more information.
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
#[derive(Clone)]
pub struct Chunks<'a, I: 'a>
pub struct Chunks<'a, I>
where
I: Iterator,
I: Iterator + 'a,
I::Item: 'a,
{
parent: &'a IntoChunks<I>,
Expand Down Expand Up @@ -568,9 +572,9 @@ where
/// An iterator for the elements in a single chunk.
///
/// Iterator element type is `I::Item`.
pub struct Chunk<'a, I: 'a>
pub struct Chunk<'a, I>
where
I: Iterator,
I: Iterator + 'a,
I::Item: 'a,
{
parent: &'a IntoChunks<I>,
Expand Down
4 changes: 2 additions & 2 deletions src/kmerge_impl.rs
Expand Up @@ -27,9 +27,9 @@ where
I: Iterator,
{
/// Constructs a `HeadTail` from an `Iterator`. Returns `None` if the `Iterator` is empty.
fn new(mut it: I) -> Option<HeadTail<I>> {
fn new(mut it: I) -> Option<Self> {
let head = it.next();
head.map(|h| HeadTail { head: h, tail: it })
head.map(|h| Self { head: h, tail: it })
}

/// Get the next element and update `head`, returning the old head in `Some`.
Expand Down
4 changes: 2 additions & 2 deletions src/lazy_buffer.rs
Expand Up @@ -14,8 +14,8 @@ impl<I> LazyBuffer<I>
where
I: Iterator,
{
pub fn new(it: I) -> LazyBuffer<I> {
LazyBuffer {
pub fn new(it: I) -> Self {
Self {
it: it.fuse(),
buffer: Vec::new(),
}
Expand Down
11 changes: 5 additions & 6 deletions src/lib.rs
Expand Up @@ -2124,8 +2124,7 @@ pub trait Itertools: Iterator {
/// ```
fn dropping_back(mut self, n: usize) -> Self
where
Self: Sized,
Self: DoubleEndedIterator,
Self: Sized + DoubleEndedIterator,
{
if n > 0 {
(&mut self).rev().nth(n - 1);
Expand Down Expand Up @@ -3962,7 +3961,7 @@ pub trait Itertools: Iterator {
}
}

impl<T: ?Sized> Itertools for T where T: Iterator {}
impl<T> Itertools for T where T: Iterator + ?Sized {}

/// Return `true` if both iterables produce equal sequences
/// (elements pairwise equal and sequences of the same length),
Expand Down Expand Up @@ -4077,15 +4076,15 @@ impl<T> FoldWhile<T> {
/// Return the value in the continue or done.
pub fn into_inner(self) -> T {
match self {
FoldWhile::Continue(x) | FoldWhile::Done(x) => x,
Self::Continue(x) | Self::Done(x) => x,
}
}

/// Return true if `self` is `Done`, false if it is `Continue`.
pub fn is_done(&self) -> bool {
match *self {
FoldWhile::Continue(_) => false,
FoldWhile::Done(_) => true,
Self::Continue(_) => false,
Self::Done(_) => true,
}
}
}
6 changes: 3 additions & 3 deletions src/minmax.rs
Expand Up @@ -37,9 +37,9 @@ impl<T: Clone> MinMaxResult<T> {
/// ```
pub fn into_option(self) -> Option<(T, T)> {
match self {
MinMaxResult::NoElements => None,
MinMaxResult::OneElement(x) => Some((x.clone(), x)),
MinMaxResult::MinMax(x, y) => Some((x, y)),
Self::NoElements => None,
Self::OneElement(x) => Some((x.clone(), x)),
Self::MinMax(x, y) => Some((x, y)),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/peeking_take_while.rs
Expand Up @@ -96,17 +96,17 @@ where
/// See [`.peeking_take_while()`](crate::Itertools::peeking_take_while)
/// for more information.
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
pub struct PeekingTakeWhile<'a, I: 'a, F>
pub struct PeekingTakeWhile<'a, I, F>
where
I: Iterator,
I: Iterator + 'a,
{
iter: &'a mut I,
f: F,
}

impl<'a, I: 'a, F> std::fmt::Debug for PeekingTakeWhile<'a, I, F>
impl<'a, I, F> std::fmt::Debug for PeekingTakeWhile<'a, I, F>
where
I: Iterator + std::fmt::Debug,
I: Iterator + std::fmt::Debug + 'a,
{
debug_fmt_fields!(PeekingTakeWhile, iter);
}
Expand Down
4 changes: 2 additions & 2 deletions src/tuple_impl.rs
Expand Up @@ -34,7 +34,7 @@ where
T: HomogeneousTuple,
{
fn new(buf: T::Buffer) -> Self {
TupleBuffer { cur: 0, buf }
Self { cur: 0, buf }
}
}

Expand Down Expand Up @@ -244,7 +244,7 @@ where
/// information.
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
#[derive(Debug, Clone)]
pub struct CircularTupleWindows<I, T: Clone>
pub struct CircularTupleWindows<I, T>
where
I: Iterator<Item = T::Item> + Clone,
T: TupleCollect + Clone,
Expand Down
2 changes: 1 addition & 1 deletion src/zip_longest.rs
Expand Up @@ -59,7 +59,7 @@ where
Self: Sized,
F: FnMut(B, Self::Item) -> B,
{
let ZipLongest { a, mut b } = self;
let Self { a, mut b } = self;
init = a.fold(init, |init, a| match b.next() {
Some(b) => f(init, EitherOrBoth::Both(a, b)),
None => f(init, EitherOrBoth::Left(a)),
Expand Down
3 changes: 1 addition & 2 deletions src/ziptuple.rs
Expand Up @@ -39,8 +39,7 @@ pub struct Zip<T> {
/// [`izip!()`]: crate::izip
pub fn multizip<T, U>(t: U) -> Zip<T>
where
Zip<T>: From<U>,
Zip<T>: Iterator,
Zip<T>: From<U> + Iterator,
{
Zip::from(t)
}
Expand Down