Skip to content

Add doc examples for iter flatten #78776

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

Closed
wants to merge 1 commit into from
Closed
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
28 changes: 24 additions & 4 deletions library/core/src/iter/adapters/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ use super::Map;
///
/// This `struct` is created by [`Iterator::flat_map`]. See its documentation
/// for more.
///
/// # Examples
///
/// ```
/// use core::iter::FlatMap;
/// use core::slice::Iter;
/// use core::str::Chars;
///
/// let words = ["yesterday", "today", "tomorrow"];
/// let iter: FlatMap<Iter<&str>, Chars, _> = words.iter().flat_map(|s| s.chars());
/// let v: Vec<char> = iter.collect();
/// ```
#[must_use = "iterators are lazy and do nothing unless consumed"]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct FlatMap<I, U: IntoIterator, F> {
Expand Down Expand Up @@ -118,11 +130,19 @@ where
/// An iterator that flattens one level of nesting in an iterator of things
/// that can be turned into iterators.
///
/// This `struct` is created by the [`flatten`] method on [`Iterator`]. See its
/// documentation for more.
/// This `struct` is created by [`Iterator::flatten`]. See its documentation
/// for more.
///
/// # Examples
///
/// ```
/// use core::iter::Flatten;
/// use core::slice::Iter;
///
/// [`flatten`]: trait.Iterator.html#method.flatten
/// [`Iterator`]: trait.Iterator.html
/// let a = [vec!['z', 'e', 'r', 'o'], vec!['o', 'n', 'e']];
/// let iter: Flatten<Iter<Vec<char>>> = a.iter().flatten();
/// let v: Vec<&char> = iter.collect();
/// ```
#[must_use = "iterators are lazy and do nothing unless consumed"]
#[stable(feature = "iterator_flatten", since = "1.29.0")]
pub struct Flatten<I: Iterator<Item: IntoIterator>> {
Expand Down