Skip to content

Commit 7ddcdc9

Browse files
authored
Merge branch 'master' into no_warn
2 parents 352bd2d + a104321 commit 7ddcdc9

File tree

6 files changed

+82
-37
lines changed

6 files changed

+82
-37
lines changed

.github/workflows/ci.yml

+11-14
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,34 @@ on:
99

1010
jobs:
1111
check:
12-
name: check
1312
runs-on: ubuntu-latest
1413
strategy:
1514
matrix:
16-
build: [msrv, stable]
1715
features:
1816
[
1917
"",
2018
"--no-default-features",
2119
"--no-default-features --features use_alloc",
2220
"--all-targets --all-features",
2321
]
24-
include:
25-
- build: msrv
26-
rust: 1.62.1
27-
- build: stable
28-
rust: stable
29-
exclude:
30-
- build: msrv
31-
# we only care about the MSRV with respect to the lib target
32-
features: "--all-targets --all-features"
3322
steps:
3423
- uses: actions/checkout@v4
35-
- uses: dtolnay/rust-toolchain@master
24+
- uses: dtolnay/rust-toolchain@stable
3625
with:
3726
toolchain: ${{ matrix.rust }}
3827
- run: RUSTFLAGS="--deny warnings" cargo check ${{ matrix.features }}
3928

29+
msrv:
30+
runs-on: ubuntu-latest
31+
env:
32+
CARGO_NET_GIT_FETCH_WITH_CLI: true
33+
steps:
34+
- uses: actions/checkout@v4
35+
- uses: taiki-e/install-action@cargo-no-dev-deps
36+
- uses: dtolnay/[email protected]
37+
- run: cargo no-dev-deps check
38+
4039
test:
41-
name: test
4240
runs-on: ubuntu-latest
4341
steps:
4442
- uses: actions/checkout@v4
@@ -62,7 +60,6 @@ jobs:
6260
if: success()
6361
runs-on: ubuntu-latest
6462
needs: [check, test]
65-
6663
steps:
6764
- name: Mark the job as successful
6865
run: exit 0

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ exclude = ["/bors.toml"]
1616

1717
edition = "2018"
1818

19-
rust-version = "1.36.0"
19+
rust-version = "1.43.1"
2020

2121
[lib]
2222
bench = false

src/lib.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
//!
4343
//! ## Rust Version
4444
//!
45-
//! This version of itertools requires Rust 1.36 or later.
45+
//! This version of itertools requires Rust 1.43.1 or later.
4646
#![doc(html_root_url = "https://docs.rs/itertools/0.11/")]
4747

4848
#[cfg(not(feature = "use_std"))]
@@ -2373,7 +2373,9 @@ pub trait Itertools: Iterator {
23732373
/// For example the sequence *Ok(1), Ok(2), Ok(3)* will result in a
23742374
/// computation like this:
23752375
///
2376-
/// ```ignore
2376+
/// ```no_run
2377+
/// # let start = 0;
2378+
/// # let f = |x, y| x + y;
23772379
/// let mut accum = start;
23782380
/// accum = f(accum, 1);
23792381
/// accum = f(accum, 2);
@@ -3981,9 +3983,10 @@ where
39813983
/// **Panics** on assertion failure with a message that shows the
39823984
/// two iteration elements.
39833985
///
3984-
/// ```ignore
3986+
/// ```should_panic
3987+
/// # use itertools::assert_equal;
39853988
/// assert_equal("exceed".split('c'), "excess".split('c'));
3986-
/// // ^PANIC: panicked at 'Failed assertion Some("eed") == Some("ess") for iteration 1',
3989+
/// // ^PANIC: panicked at 'Failed assertion Some("eed") == Some("ess") for iteration 1'.
39873990
/// ```
39883991
pub fn assert_equal<I, J>(a: I, b: J)
39893992
where

src/size_hint.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,6 @@ pub fn sub_scalar(sh: SizeHint, x: usize) -> SizeHint {
3939
}
4040

4141
/// Multiply `SizeHint` correctly
42-
///
43-
/// ```ignore
44-
/// use std::usize;
45-
/// use itertools::size_hint;
46-
///
47-
/// assert_eq!(size_hint::mul((3, Some(4)), (3, Some(4))),
48-
/// (9, Some(16)));
49-
///
50-
/// assert_eq!(size_hint::mul((3, Some(4)), (usize::MAX, None)),
51-
/// (usize::MAX, None));
52-
///
53-
/// assert_eq!(size_hint::mul((3, None), (0, Some(0))),
54-
/// (0, Some(0)));
55-
/// ```
5642
#[inline]
5743
pub fn mul(a: SizeHint, b: SizeHint) -> SizeHint {
5844
let low = a.0.saturating_mul(b.0);
@@ -101,3 +87,10 @@ pub fn min(a: SizeHint, b: SizeHint) -> SizeHint {
10187
};
10288
(lower, upper)
10389
}
90+
91+
#[test]
92+
fn mul_size_hints() {
93+
assert_eq!(mul((3, Some(4)), (3, Some(4))), (9, Some(16)));
94+
assert_eq!(mul((3, Some(4)), (usize::MAX, None)), (usize::MAX, None));
95+
assert_eq!(mul((3, None), (0, Some(0))), (0, Some(0)));
96+
}

src/tuple_impl.rs

+44-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use std::iter::Cycle;
44
use std::iter::Fuse;
55
use std::iter::FusedIterator;
6-
use std::iter::Take;
76
use std::marker::PhantomData;
87

98
// `HomogeneousTuple` is a public facade for `TupleCollect`, allowing
@@ -185,6 +184,20 @@ where
185184
}
186185
None
187186
}
187+
188+
fn size_hint(&self) -> (usize, Option<usize>) {
189+
// At definition, `T::num_items() - 1` are collected
190+
// so each remaining item in `iter` will lead to an item.
191+
self.iter.size_hint()
192+
}
193+
}
194+
195+
impl<I, T> ExactSizeIterator for TupleWindows<I, T>
196+
where
197+
I: ExactSizeIterator<Item = T::Item>,
198+
T: HomogeneousTuple + Clone,
199+
T::Item: Clone,
200+
{
188201
}
189202

190203
impl<I, T> FusedIterator for TupleWindows<I, T>
@@ -208,7 +221,8 @@ where
208221
I: Iterator<Item = T::Item> + Clone,
209222
T: TupleCollect + Clone,
210223
{
211-
iter: Take<TupleWindows<Cycle<I>, T>>,
224+
iter: TupleWindows<Cycle<I>, T>,
225+
len: usize,
212226
phantom_data: PhantomData<T>,
213227
}
214228

@@ -219,10 +233,11 @@ where
219233
T::Item: Clone,
220234
{
221235
let len = iter.len();
222-
let iter = tuple_windows(iter.cycle()).take(len);
236+
let iter = tuple_windows(iter.cycle());
223237

224238
CircularTupleWindows {
225239
iter,
240+
len,
226241
phantom_data: PhantomData {},
227242
}
228243
}
@@ -236,10 +251,35 @@ where
236251
type Item = T;
237252

238253
fn next(&mut self) -> Option<Self::Item> {
239-
self.iter.next()
254+
if self.len != 0 {
255+
self.len -= 1;
256+
self.iter.next()
257+
} else {
258+
None
259+
}
260+
}
261+
262+
fn size_hint(&self) -> (usize, Option<usize>) {
263+
(self.len, Some(self.len))
240264
}
241265
}
242266

267+
impl<I, T> ExactSizeIterator for CircularTupleWindows<I, T>
268+
where
269+
I: Iterator<Item = T::Item> + Clone,
270+
T: TupleCollect + Clone,
271+
T::Item: Clone,
272+
{
273+
}
274+
275+
impl<I, T> FusedIterator for CircularTupleWindows<I, T>
276+
where
277+
I: Iterator<Item = T::Item> + Clone,
278+
T: TupleCollect + Clone,
279+
T::Item: Clone,
280+
{
281+
}
282+
243283
pub trait TupleCollect: Sized {
244284
type Item;
245285
type Buffer: Default + AsRef<[Option<Self::Item>]> + AsMut<[Option<Self::Item>]>;

tests/quick.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,10 @@ quickcheck! {
11191119
true
11201120
}
11211121

1122+
fn circular_tuple_windows_exact_size(a: Vec<u8>) -> bool {
1123+
exact_size(a.iter().circular_tuple_windows::<(_, _, _, _)>())
1124+
}
1125+
11221126
fn equal_tuple_windows_1(a: Vec<u8>) -> bool {
11231127
let x = a.windows(1).map(|s| (&s[0], ));
11241128
let y = a.iter().tuple_windows::<(_,)>();
@@ -1143,6 +1147,14 @@ quickcheck! {
11431147
itertools::equal(x, y)
11441148
}
11451149

1150+
fn tuple_windows_exact_size_1(a: Vec<u8>) -> bool {
1151+
exact_size(a.iter().tuple_windows::<(_,)>())
1152+
}
1153+
1154+
fn tuple_windows_exact_size_4(a: Vec<u8>) -> bool {
1155+
exact_size(a.iter().tuple_windows::<(_, _, _, _)>())
1156+
}
1157+
11461158
fn equal_tuples_1(a: Vec<u8>) -> bool {
11471159
let x = a.chunks(1).map(|s| (&s[0], ));
11481160
let y = a.iter().tuples::<(_,)>();

0 commit comments

Comments
 (0)