mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
Improve Iterator::intersperse_ docs
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
/// An iterator adapter that places a separator between all elements.
|
||||
///
|
||||
/// This `struct` is created by [`Iterator::intersperse`]. See it's documentation
|
||||
/// This `struct` is created by [`Iterator::intersperse`]. See its documentation
|
||||
/// for more information.
|
||||
#[unstable(feature = "iter_intersperse", reason = "recently added", issue = "79524")]
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -59,7 +59,7 @@ fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
|
||||
/// An iterator adapter that places a separator between all elements.
|
||||
///
|
||||
/// This `struct` is created by [`Iterator::intersperse_with`]. See it's
|
||||
/// This `struct` is created by [`Iterator::intersperse_with`]. See its
|
||||
/// documentation for more information.
|
||||
#[unstable(feature = "iter_intersperse", reason = "recently added", issue = "79524")]
|
||||
pub struct IntersperseWith<I, G>
|
||||
|
||||
@@ -571,6 +571,9 @@ fn zip<U>(self, other: U) -> Zip<Self, U::IntoIter>
|
||||
|
||||
/// Places a copy of `separator` between all elements.
|
||||
///
|
||||
/// In case the separator does not implement [`Clone`] or needs to be
|
||||
/// computed every time, use [`intersperse_with`].
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
@@ -578,9 +581,12 @@ fn zip<U>(self, other: U) -> Zip<Self, U::IntoIter>
|
||||
/// ```
|
||||
/// #![feature(iter_intersperse)]
|
||||
///
|
||||
/// let hello = ["Hello", "World"].iter().copied().intersperse(" ").collect::<String>();
|
||||
/// assert_eq!(hello, "Hello World");
|
||||
/// let hello = ["Hello", "World", "!"].iter().copied().intersperse(" ").collect::<String>();
|
||||
/// assert_eq!(hello, "Hello World !");
|
||||
/// ```
|
||||
///
|
||||
/// [`Clone`]: crate::clone::Clone
|
||||
/// [`intersperse_with`]: Iterator::intersperse_with
|
||||
#[inline]
|
||||
#[unstable(feature = "iter_intersperse", reason = "recently added", issue = "79524")]
|
||||
fn intersperse(self, separator: Self::Item) -> Intersperse<Self>
|
||||
@@ -600,11 +606,13 @@ fn intersperse(self, separator: Self::Item) -> Intersperse<Self>
|
||||
/// ```
|
||||
/// #![feature(iter_intersperse)]
|
||||
///
|
||||
/// let src = ["Hello", "to", "all", "people"].iter().copied();
|
||||
/// let mut separator = [" ❤️ ", " 😀 "].iter().copied().cycle();
|
||||
/// let src = ["Hello", "to", "all", "people", "!!"].iter().copied();
|
||||
///
|
||||
/// let result = src.intersperse_with(|| separator.next().unwrap()).collect::<String>();
|
||||
/// assert_eq!(result, "Hello ❤️ to 😀 all ❤️ people");
|
||||
/// let mut happy_emojis = [" ❤️ ", " 😀 "].iter().copied();
|
||||
/// let separator = || happy_emojis.next().unwrap_or(" 🦀 ");
|
||||
///
|
||||
/// let result = src.intersperse_with(separator).collect::<String>();
|
||||
/// assert_eq!(result, "Hello ❤️ to 😀 all 🦀 people 🦀 !!");
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "iter_intersperse", reason = "recently added", issue = "79524")]
|
||||
|
||||
Reference in New Issue
Block a user