Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nixphix committed Aug 30, 2020
1 parent 8a92718 commit 01d95f2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
27 changes: 13 additions & 14 deletions library/core/src/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ pub const fn identity<T>(x: T) -> T {
/// want to accept all references that can be converted to [`&str`] as an argument.
/// Since both [`String`] and [`&str`] implement `AsRef<str>` we can accept both as input argument.
///
/// [`Option<T>`]: crate::option::Option
/// [`Result<T, E>`]: crate::result::Result
/// [`Option<T>`]: Option
/// [`Result<T, E>`]: Result
/// [`Borrow`]: crate::borrow::Borrow
/// [`Eq`]: crate::cmp::Eq
/// [`Ord`]: crate::cmp::Ord
Expand Down Expand Up @@ -168,8 +168,8 @@ pub trait AsRef<T: ?Sized> {
/// **Note: This trait must not fail**. If the conversion can fail, use a
/// dedicated method which returns an [`Option<T>`] or a [`Result<T, E>`].
///
/// [`Option<T>`]: crate::option::Option
/// [`Result<T, E>`]: crate::result::Result
/// [`Option<T>`]: Option
/// [`Result<T, E>`]: Result
///
/// # Generic Implementations
///
Expand All @@ -195,7 +195,7 @@ pub trait AsRef<T: ?Sized> {
/// assert_eq!(*boxed_num, 1);
/// ```
///
/// [`Box<T>`]: crate::boxed::Box<T>
/// [`Box<T>`]: ../../std/boxed/struct.Box.html
#[stable(feature = "rust1", since = "1.0.0")]
pub trait AsMut<T: ?Sized> {
/// Performs the conversion.
Expand Down Expand Up @@ -269,10 +269,10 @@ pub trait AsMut<T: ?Sized> {
/// is_hello(s);
/// ```
///
/// [`Option<T>`]: crate::option::Option
/// [`Result<T, E>`]: crate::result::Result
/// [`Option<T>`]: Option
/// [`Result<T, E>`]: Result
/// [`String`]: ../../std/string/struct.String.html
/// [`Vec`]: crate::vec::Vec<T>
/// [`Vec`]: ../../std/vec/struct.Vec.html
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Into<T>: Sized {
/// Performs the conversion.
Expand Down Expand Up @@ -358,9 +358,10 @@ pub trait Into<T>: Sized {
/// }
/// ```
///
/// [`Option<T>`]: crate::option::Option
/// [`Result<T, E>`]: crate::result::Result
/// [`Option<T>`]: Option
/// [`Result<T, E>`]: Result
/// [`String`]: ../../std/string/struct.String.html
/// [`from`]: From::from
/// [book]: ../../book/ch09-00-error-handling.html
#[rustc_diagnostic_item = "from_trait"]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -418,7 +419,7 @@ pub trait TryInto<T>: Sized {
/// # Generic Implementations
///
/// - `TryFrom<T> for U` implies [`TryInto`]`<U> for T`
/// - [`TryFrom::try_from`] is reflexive, which means that `TryFrom<T> for T`
/// - [`try_from`] is reflexive, which means that `TryFrom<T> for T`
/// is implemented and cannot fail -- the associated `Error` type for
/// calling `T::try_from()` on a value of type `T` is [`Infallible`].
/// When the [`!`] type is stabilized [`Infallible`] and [`!`] will be
Expand Down Expand Up @@ -467,7 +468,7 @@ pub trait TryInto<T>: Sized {
/// assert!(try_successful_smaller_number.is_ok());
/// ```
///
/// [`i32::MAX`]: crate::i32::MAX
/// [`try_from`]: TryFrom::try_from
/// [`!`]: ../../std/primitive.never.html
#[stable(feature = "try_from", since = "1.34.0")]
pub trait TryFrom<T>: Sized {
Expand Down Expand Up @@ -670,8 +671,6 @@ impl AsRef<str> for str {
/// the two `impl`s will start to overlap
/// and therefore will be disallowed by the language’s trait coherence rules.
///
/// [`Ok`]: super::result::Result::Ok
/// [`Result`]: super::result::Result
/// [never]: ../../std/primitive.never.html
#[stable(feature = "convert_infallible", since = "1.34.0")]
#[derive(Copy)]
Expand Down
30 changes: 22 additions & 8 deletions library/core/src/iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,13 @@
//! produce an iterator. What gives?
//!
//! There's a trait in the standard library for converting something into an
//! iterator: [`IntoIterator`]. This trait has one method, [`IntoIterator::into_iter`],
//! iterator: [`IntoIterator`]. This trait has one method, [`into_iter`],
//! which converts the thing implementing [`IntoIterator`] into an iterator.
//! Let's take a look at that `for` loop again, and what the compiler converts
//! it into:
//!
//! [`into_iter`]: IntoIterator::into_iter
//!
//! ```
//! let values = vec![1, 2, 3, 4, 5];
//!
Expand Down Expand Up @@ -209,20 +211,24 @@
//! often called 'iterator adapters', as they're a form of the 'adapter
//! pattern'.
//!
//! Common iterator adapters include [`Iterator::map`], [`Iterator::take`], and [`Iterator::filter`].
//! Common iterator adapters include [`map`], [`take`], and [`filter`].
//! For more, see their documentation.
//!
//! If an iterator adapter panics, the iterator will be in an unspecified (but
//! memory safe) state. This state is also not guaranteed to stay the same
//! across versions of Rust, so you should avoid relying on the exact values
//! returned by an iterator which panicked.
//!
//! [`map`]: Iterator::map
//! [`take`]: Iterator::take
//! [`filter`]: Iterator::filter
//!
//! # Laziness
//!
//! Iterators (and iterator [adapters](#adapters)) are *lazy*. This means that
//! just creating an iterator doesn't _do_ a whole lot. Nothing really happens
//! until you call [`next`]. This is sometimes a source of confusion when
//! creating an iterator solely for its side effects. For example, the [`Iterator::map`]
//! creating an iterator solely for its side effects. For example, the [`map`]
//! method calls a closure on each element it iterates over:
//!
//! ```
Expand All @@ -239,8 +245,8 @@
//! do nothing unless consumed
//! ```
//!
//! The idiomatic way to write a [`Iterator::map`] for its side effects is to use a
//! `for` loop or call the [`Iterator::for_each`] method:
//! The idiomatic way to write a [`map`] for its side effects is to use a
//! `for` loop or call the [`for_each`] method:
//!
//! ```
//! let v = vec![1, 2, 3, 4, 5];
Expand All @@ -252,9 +258,14 @@
//! }
//! ```
//!
//! Another common way to evaluate an iterator is to use the [`Iterator::collect`]
//! [`map`]: Iterator::map
//! [`for_each`]: Iterator::for_each
//!
//! Another common way to evaluate an iterator is to use the [`collect`]
//! method to produce a new collection.
//!
//! [`collect`]: Iterator::collect
//!
//! # Infinity
//!
//! Iterators do not have to be finite. As an example, an open-ended range is
Expand All @@ -264,7 +275,7 @@
//! let numbers = 0..;
//! ```
//!
//! It is common to use the [`Iterator::take`] iterator adapter to turn an infinite
//! It is common to use the [`take`] iterator adapter to turn an infinite
//! iterator into a finite one:
//!
//! ```
Expand All @@ -280,7 +291,7 @@
//!
//! Bear in mind that methods on infinite iterators, even those for which a
//! result can be determined mathematically in finite time, may not terminate.
//! Specifically, methods such as [`Iterator::min`], which in the general case require
//! Specifically, methods such as [`min`], which in the general case require
//! traversing every element in the iterator, are likely not to return
//! successfully for any infinite iterators.
//!
Expand All @@ -290,6 +301,9 @@
//! // `ones.min()` causes an infinite loop, so we won't reach this point!
//! println!("The smallest number one is {}.", least);
//! ```
//!
//! [`take`]: Iterator::take
//! [`min`]: Iterator::min
#![stable(feature = "rust1", since = "1.0.0")]

Expand Down

0 comments on commit 01d95f2

Please sign in to comment.