Skip to content

Commit

Permalink
Fix/ignore warnings within doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe-Cholet committed Jul 3, 2024
1 parent e41a62b commit 3067893
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/free.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub use crate::zip_eq_impl::zip_eq;
/// ```
/// use itertools::intersperse;
///
/// itertools::assert_equal(intersperse((0..3), 8), vec![0, 8, 1, 8, 2]);
/// itertools::assert_equal(intersperse(0..3, 8), vec![0, 8, 1, 8, 2]);
/// ```
pub fn intersperse<I>(iterable: I, element: I::Item) -> Intersperse<I::IntoIter>
where
Expand All @@ -55,7 +55,7 @@ where
/// use itertools::intersperse_with;
///
/// let mut i = 10;
/// itertools::assert_equal(intersperse_with((0..3), || { i -= 1; i }), vec![0, 9, 1, 8, 2]);
/// itertools::assert_equal(intersperse_with(0..3, || { i -= 1; i }), vec![0, 9, 1, 8, 2]);
/// assert_eq!(i, 8);
/// ```
pub fn intersperse_with<I, F>(iterable: I, element: F) -> IntersperseWith<I::IntoIter, F>
Expand All @@ -75,6 +75,7 @@ where
///
/// for (i, elt) in enumerate(&[1, 2, 3]) {
/// /* loop body */
/// # let _ = (i, elt);
/// }
/// ```
pub fn enumerate<I>(iterable: I) -> iter::Enumerate<I::IntoIter>
Expand All @@ -93,6 +94,7 @@ where
///
/// for elt in rev(&[1, 2, 3]) {
/// /* loop body */
/// # let _ = elt;
/// }
/// ```
pub fn rev<I>(iterable: I) -> iter::Rev<I::IntoIter>
Expand Down
1 change: 1 addition & 0 deletions src/kmerge_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ impl<T, F: FnMut(&T, &T) -> bool> KMergePredicate<T> for F {
///
/// for elt in kmerge(vec![vec![0, 2, 4], vec![1, 3, 5], vec![6, 7]]) {
/// /* loop body */
/// # let _ = elt;
/// }
/// ```
pub fn kmerge<I>(iterable: I) -> KMerge<<I::Item as IntoIterator>::IntoIter>
Expand Down
31 changes: 20 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#![warn(missing_docs, clippy::default_numeric_fallback)]
#![crate_name = "itertools"]
#![cfg_attr(not(feature = "use_std"), no_std)]
#![doc(test(attr(deny(warnings), allow(deprecated, unstable_name_collisions))))]

//! Extra iterator adaptors, functions and macros.
//!
//! To extend [`Iterator`] with methods in this crate, import
//! the [`Itertools`] trait:
//!
//! ```
//! # #[allow(unused_imports)]
//! use itertools::Itertools;
//! ```
//!
Expand All @@ -29,6 +31,7 @@
//!
//! for elt in interleave(&[1, 2, 3], &[2, 3, 4]) {
//! /* loop body */
//! # let _ = elt;
//! }
//! ```
//!
Expand Down Expand Up @@ -248,6 +251,7 @@ mod ziptuple;
/// // from (0, 0, 0), (0, 0, 1), .., (0, 1, 0), (0, 1, 1), .. etc until (3, 3, 3)
/// for (i, j, k) in iproduct!(0..4, 0..4, 0..4) {
/// // ..
/// # let _ = (i, j, k);
/// }
/// # }
/// ```
Expand Down Expand Up @@ -375,16 +379,16 @@ macro_rules! izip {
///
/// Invocations of `chain!` with one argument expand to [`arg.into_iter()`](IntoIterator):
/// ```
/// use std::{ops::Range, slice};
/// use std::ops::Range;
/// use itertools::chain;
/// let _: <Range<_> as IntoIterator>::IntoIter = chain!((2..6),); // trailing comma optional!
/// let _: <Range<_> as IntoIterator>::IntoIter = chain!(2..6,); // trailing comma optional!
/// let _: <&[_] as IntoIterator>::IntoIter = chain!(&[2, 3, 4]);
/// ```
///
/// Invocations of `chain!` with multiple arguments [`.into_iter()`](IntoIterator) each
/// argument, and then [`chain`] them together:
/// ```
/// use std::{iter::*, ops::Range, slice};
/// use std::{iter::*, slice};
/// use itertools::{assert_equal, chain};
///
/// // e.g., this:
Expand Down Expand Up @@ -1902,7 +1906,7 @@ pub trait Itertools: Iterator {
/// use itertools::Itertools;
///
/// let input = vec![vec![1], vec![3, 2, 1]];
/// let it = input.into_iter().update(|mut v| v.push(0));
/// let it = input.into_iter().update(|v| v.push(0));
/// itertools::assert_equal(it, vec![vec![1, 0], vec![3, 2, 1, 0]]);
/// ```
fn update<F>(self, updater: F) -> Update<Self, F>
Expand Down Expand Up @@ -2162,7 +2166,7 @@ pub trait Itertools: Iterator {
/// ```
/// use itertools::Itertools;
///
/// let mut iter = "αβγ".chars().dropping(2);
/// let iter = "αβγ".chars().dropping(2);
/// itertools::assert_equal(iter, "γ".chars());
/// ```
///
Expand Down Expand Up @@ -2246,14 +2250,17 @@ pub trait Itertools: Iterator {
///
/// fn process_dir_entries(entries: &[fs::DirEntry]) {
/// // ...
/// # let _ = entries;
/// }
///
/// fn do_stuff() -> std::io::Result<()> {
/// fn do_stuff() -> io::Result<()> {
/// let entries: Vec<_> = fs::read_dir(".")?.try_collect()?;
/// process_dir_entries(&entries);
///
/// Ok(())
/// }
///
/// # let _ = do_stuff;
/// ```
fn try_collect<T, U, E>(self) -> Result<U, E>
where
Expand Down Expand Up @@ -2404,6 +2411,7 @@ pub trait Itertools: Iterator {
/// accum = f(accum, 1);
/// accum = f(accum, 2);
/// accum = f(accum, 3);
/// # let _ = accum;
/// ```
///
/// With a `start` value of 0 and an addition as folding function,
Expand Down Expand Up @@ -2554,16 +2562,16 @@ pub trait Itertools: Iterator {
/// assert_eq!((1..8).map(|x| x.to_string()).tree_reduce(f),
/// Some(String::from("f(f(f(1, 2), f(3, 4)), f(f(5, 6), 7))")));
///
/// // Like fold1, an empty iterator produces None
/// // Like reduce, an empty iterator produces None
/// assert_eq!((0..0).tree_reduce(|x, y| x * y), None);
///
/// // tree_reduce matches fold1 for associative operations...
/// // tree_reduce matches reduce for associative operations...
/// assert_eq!((0..10).tree_reduce(|x, y| x + y),
/// (0..10).fold1(|x, y| x + y));
/// (0..10).reduce(|x, y| x + y));
///
/// // ...but not for non-associative ones
/// assert_ne!((0..10).tree_reduce(|x, y| x - y),
/// (0..10).fold1(|x, y| x - y));
/// (0..10).reduce(|x, y| x - y));
///
/// let mut total_len_reduce = 0;
/// let reduce_res = (1..100).map(|x| x.to_string())
Expand Down Expand Up @@ -4350,7 +4358,7 @@ pub trait Itertools: Iterator {
/// # Examples
/// ```
/// # use itertools::Itertools;
/// let counts = [1, 1, 1, 3, 3, 5].into_iter().counts();
/// let counts = [1, 1, 1, 3, 3, 5].iter().counts();
/// assert_eq!(counts[&1], 3);
/// assert_eq!(counts[&3], 2);
/// assert_eq!(counts[&5], 1);
Expand All @@ -4376,6 +4384,7 @@ pub trait Itertools: Iterator {
/// # use itertools::Itertools;
/// struct Character {
/// first_name: &'static str,
/// # #[allow(dead_code)]
/// last_name: &'static str,
/// }
///
Expand Down
1 change: 1 addition & 0 deletions src/merge_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub type Merge<I, J> = MergeBy<I, J, MergeLte>;
///
/// for elt in merge(&[1, 2, 3], &[2, 3, 4]) {
/// /* loop body */
/// # let _ = elt;
/// }
/// ```
pub fn merge<I, J>(
Expand Down
1 change: 1 addition & 0 deletions src/zip_eq_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct ZipEq<I, J> {
/// let data = [1, 2, 3, 4, 5];
/// for (a, b) in zip_eq(&data[..data.len() - 1], &data[1..]) {
/// /* loop body */
/// # let _ = (a, b);
/// }
/// ```
pub fn zip_eq<I, J>(i: I, j: J) -> ZipEq<I::IntoIter, J::IntoIter>
Expand Down

0 comments on commit 3067893

Please sign in to comment.