Skip to content

Commit ba0ddf2

Browse files
committed
fix: take_while_inclusive takes iterator by value
this helps in case TakeWhileInclusive is returned from a function, as otherwise we would be returning a struct which takes a reference from a locally created iterator.
1 parent 62a6401 commit ba0ddf2

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ pub trait Itertools : Iterator {
15191519
/// .collect();
15201520
/// let expected: Vec<_> = vec![1, 2, 3].into_iter().map(NoCloneImpl).collect();
15211521
/// assert_eq!(filtered, expected);
1522-
fn take_while_inclusive<F>(&mut self, accept: F) -> TakeWhileInclusive<Self, F>
1522+
fn take_while_inclusive<F>(self, accept: F) -> TakeWhileInclusive<Self, F>
15231523
where
15241524
Self: Sized,
15251525
F: FnMut(&Self::Item) -> bool,
@@ -2650,7 +2650,7 @@ pub trait Itertools : Iterator {
26502650
/// **Note:** This consumes the entire iterator, uses the
26512651
/// [`slice::sort_unstable`] method and returns the result as a new
26522652
/// iterator that owns its elements.
2653-
///
2653+
///
26542654
/// This sort is unstable (i.e., may reorder equal elements).
26552655
///
26562656
/// The sorted iterator, if directly collected to a `Vec`, is converted
@@ -2681,7 +2681,7 @@ pub trait Itertools : Iterator {
26812681
/// **Note:** This consumes the entire iterator, uses the
26822682
/// [`slice::sort_unstable_by`] method and returns the result as a new
26832683
/// iterator that owns its elements.
2684-
///
2684+
///
26852685
/// This sort is unstable (i.e., may reorder equal elements).
26862686
///
26872687
/// The sorted iterator, if directly collected to a `Vec`, is converted
@@ -2716,7 +2716,7 @@ pub trait Itertools : Iterator {
27162716
/// **Note:** This consumes the entire iterator, uses the
27172717
/// [`slice::sort_unstable_by_key`] method and returns the result as a new
27182718
/// iterator that owns its elements.
2719-
///
2719+
///
27202720
/// This sort is unstable (i.e., may reorder equal elements).
27212721
///
27222722
/// The sorted iterator, if directly collected to a `Vec`, is converted
@@ -2752,7 +2752,7 @@ pub trait Itertools : Iterator {
27522752
/// **Note:** This consumes the entire iterator, uses the
27532753
/// [`slice::sort`] method and returns the result as a new
27542754
/// iterator that owns its elements.
2755-
///
2755+
///
27562756
/// This sort is stable (i.e., does not reorder equal elements).
27572757
///
27582758
/// The sorted iterator, if directly collected to a `Vec`, is converted
@@ -2783,7 +2783,7 @@ pub trait Itertools : Iterator {
27832783
/// **Note:** This consumes the entire iterator, uses the
27842784
/// [`slice::sort_by`] method and returns the result as a new
27852785
/// iterator that owns its elements.
2786-
///
2786+
///
27872787
/// This sort is stable (i.e., does not reorder equal elements).
27882788
///
27892789
/// The sorted iterator, if directly collected to a `Vec`, is converted
@@ -2818,7 +2818,7 @@ pub trait Itertools : Iterator {
28182818
/// **Note:** This consumes the entire iterator, uses the
28192819
/// [`slice::sort_by_key`] method and returns the result as a new
28202820
/// iterator that owns its elements.
2821-
///
2821+
///
28222822
/// This sort is stable (i.e., does not reorder equal elements).
28232823
///
28242824
/// The sorted iterator, if directly collected to a `Vec`, is converted
@@ -2855,7 +2855,7 @@ pub trait Itertools : Iterator {
28552855
/// **Note:** This consumes the entire iterator, uses the
28562856
/// [`slice::sort_by_cached_key`] method and returns the result as a new
28572857
/// iterator that owns its elements.
2858-
///
2858+
///
28592859
/// This sort is stable (i.e., does not reorder equal elements).
28602860
///
28612861
/// The sorted iterator, if directly collected to a `Vec`, is converted

src/take_while_inclusive.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,30 @@ use std::fmt;
88
/// See [`.take_while_inclusive()`](crate::Itertools::take_while_inclusive)
99
/// for more information.
1010
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
11-
pub struct TakeWhileInclusive<'a, I: 'a, F> {
12-
iter: &'a mut I,
11+
pub struct TakeWhileInclusive<I, F> {
12+
iter: I,
1313
predicate: F,
1414
done: bool,
1515
}
1616

17-
impl<'a, I, F> TakeWhileInclusive<'a, I, F>
17+
impl<I, F> TakeWhileInclusive<I, F>
1818
where
1919
I: Iterator,
2020
F: FnMut(&I::Item) -> bool,
2121
{
2222
/// Create a new [`TakeWhileInclusive`] from an iterator and a predicate.
23-
pub fn new(iter: &'a mut I, predicate: F) -> Self {
23+
pub fn new(iter: I, predicate: F) -> Self {
2424
Self { iter, predicate, done: false}
2525
}
2626
}
2727

28-
impl<'a, I, F> fmt::Debug for TakeWhileInclusive<'a, I, F>
28+
impl<I, F> fmt::Debug for TakeWhileInclusive<I, F>
2929
where I: Iterator + fmt::Debug,
3030
{
3131
debug_fmt_fields!(TakeWhileInclusive, iter);
3232
}
3333

34-
impl<'a, I, F> Iterator for TakeWhileInclusive<'a, I, F>
34+
impl<I, F> Iterator for TakeWhileInclusive<I, F>
3535
where
3636
I: Iterator,
3737
F: FnMut(&I::Item) -> bool
@@ -60,9 +60,9 @@ where
6060
}
6161
}
6262

63-
impl<I, F> FusedIterator for TakeWhileInclusive<'_, I, F>
63+
impl<I, F> FusedIterator for TakeWhileInclusive<I, F>
6464
where
6565
I: Iterator,
6666
F: FnMut(&I::Item) -> bool
6767
{
68-
}
68+
}

0 commit comments

Comments
 (0)