From c956fe5cea5c2221e54a98b6f83214b08eb5ce24 Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 3 Mar 2022 19:45:53 -0500 Subject: [PATCH 1/3] Document new recommended use of method --- library/core/src/iter/traits/collect.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/library/core/src/iter/traits/collect.rs b/library/core/src/iter/traits/collect.rs index 637d7bc4488..9af3c0d4809 100644 --- a/library/core/src/iter/traits/collect.rs +++ b/library/core/src/iter/traits/collect.rs @@ -4,9 +4,11 @@ /// created from an iterator. This is common for types which describe a /// collection of some kind. /// -/// [`FromIterator::from_iter()`] is rarely called explicitly, and is instead -/// used through [`Iterator::collect()`] method. See [`Iterator::collect()`]'s -/// documentation for more examples. +/// If you want to create a collection from the contents of an iterator, the +/// [`Iterator::collect()`] method is preferred. However, the compiler is +/// sometimes unable to infer the full type of the collection. In these cases, +/// [`FromIterator::from_iter()`] can be more concise and readable. See the +/// [`Iterator::collect()`] documentation for more examples of its use. /// /// See also: [`IntoIterator`]. /// @@ -32,6 +34,17 @@ /// assert_eq!(v, vec![5, 5, 5, 5, 5]); /// ``` /// +/// Using [`FromIterator::from_iter()`] as a more readable alternative to +/// [`Iterator::collect()`]: +/// +/// ``` +/// # use std::collections::VecDeque; +/// let first = (0..10).collect::>(); +/// let second = VecDeque::from_iter(0..10); +/// +/// assert_eq!(first, second); +/// ``` +/// /// Implementing `FromIterator` for your type: /// /// ``` From 5f34c04de66c9ec98dd4f6f6d88bb6c10d21b9fb Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 4 Mar 2022 09:45:18 -0500 Subject: [PATCH 2/3] Make use statement visible --- library/core/src/iter/traits/collect.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/iter/traits/collect.rs b/library/core/src/iter/traits/collect.rs index 9af3c0d4809..28ae2277252 100644 --- a/library/core/src/iter/traits/collect.rs +++ b/library/core/src/iter/traits/collect.rs @@ -38,7 +38,7 @@ /// [`Iterator::collect()`]: /// /// ``` -/// # use std::collections::VecDeque; +/// use std::collections::VecDeque; /// let first = (0..10).collect::>(); /// let second = VecDeque::from_iter(0..10); /// From b363f130698dbc55fe594155bcb4df826ffad71e Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 4 Mar 2022 09:48:51 -0500 Subject: [PATCH 3/3] Add suggested changes to the docs --- library/core/src/iter/traits/collect.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/core/src/iter/traits/collect.rs b/library/core/src/iter/traits/collect.rs index 28ae2277252..dee66e6e072 100644 --- a/library/core/src/iter/traits/collect.rs +++ b/library/core/src/iter/traits/collect.rs @@ -5,9 +5,9 @@ /// collection of some kind. /// /// If you want to create a collection from the contents of an iterator, the -/// [`Iterator::collect()`] method is preferred. However, the compiler is -/// sometimes unable to infer the full type of the collection. In these cases, -/// [`FromIterator::from_iter()`] can be more concise and readable. See the +/// [`Iterator::collect()`] method is preferred. However, when you need to +/// specify the container type, [`FromIterator::from_iter()`] can be more +/// readable than using a turbofish (e.g. `::>()`). See the /// [`Iterator::collect()`] documentation for more examples of its use. /// /// See also: [`IntoIterator`].