From: Lzu Tao Date: Mon, 28 Oct 2019 03:22:59 +0000 (+0000) Subject: doc: introduce `once` in `iter::chain` document X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=9c4f60eecf1c9a0d90e6e2ea1e089fd77fd2c20f;p=rust.git doc: introduce `once` in `iter::chain` document --- diff --git a/src/libcore/iter/traits/iterator.rs b/src/libcore/iter/traits/iterator.rs index a272035150a..7ffc8b3729c 100644 --- a/src/libcore/iter/traits/iterator.rs +++ b/src/libcore/iter/traits/iterator.rs @@ -384,6 +384,9 @@ fn step_by(self, step: usize) -> StepBy where Self: Sized { /// /// In other words, it links two iterators together, in a chain. 🔗 /// + /// [`once`] is commonly used to adapt a single value into a chain of + /// other kinds of iteration. + /// /// # Examples /// /// Basic usage: @@ -408,9 +411,6 @@ fn step_by(self, step: usize) -> StepBy where Self: Sized { /// [`Iterator`] itself. For example, slices (`&[T]`) implement /// [`IntoIterator`], and so can be passed to `chain()` directly: /// - /// [`IntoIterator`]: trait.IntoIterator.html - /// [`Iterator`]: trait.Iterator.html - /// /// ``` /// let s1 = &[1, 2, 3]; /// let s2 = &[4, 5, 6]; @@ -425,6 +425,21 @@ fn step_by(self, step: usize) -> StepBy where Self: Sized { /// assert_eq!(iter.next(), Some(&6)); /// assert_eq!(iter.next(), None); /// ``` + /// + /// If you work with Windows API, you may wish to convert [`OsStr`] to `Vec`: + /// + /// ``` + /// #[cfg(windows)] + /// fn os_str_to_utf16(s: &std::ffi::OsStr) -> Vec { + /// use std::os::windows::ffi::OsStrExt; + /// s.encode_wide().chain(std::iter::once(0)).collect() + /// } + /// ``` + /// + /// [`once`]: fn.once.html + /// [`Iterator`]: trait.Iterator.html + /// [`IntoIterator`]: trait.IntoIterator.html + /// [`OsStr`]: ../../std/ffi/struct.OsStr.html #[inline] #[stable(feature = "rust1", since = "1.0.0")] fn chain(self, other: U) -> Chain where