2222//! - `from` is the more flexible way, which can convert values and references
2323//!
2424//! As a library writer, you should prefer implementing `From<T>` rather than
25- //! `Into<U>`, as `From` is more flexible (you can't `Into` a reference, where
26- //! you can impl `From` for a reference). `From` is also used for generic
27- //! implementations.
25+ //! `Into<U>`, as `From` provides greater flexibility and offer the equivalent `Into`
26+ //! implementation for free thanks to a blanket implementation in the standard library.
2827//!
29- //! **Note:** these traits are for trivial conversion. **They must not fail**. If
30- //! they can fail, use a dedicated method which return an `Option<T>` or
31- //! a `Result<T, E>`.
28+ //! **Note: these traits must not fail**. If the conversion can fail, you must use a dedicated
29+ //! method which return an `Option<T>` or a `Result<T, E>`.
3230//!
3331//! # Generic impl
3432//!
3533//! - `AsRef` and `AsMut` auto-dereference if the inner type is a reference
3634//! - `From<U> for T` implies `Into<T> for U`
3735//! - `From` and `Into` are reflexive, which means that all types can `into()`
38- //! themselve and `from()` themselve
36+ //! themselves and `from()` themselves
3937//!
4038//! See each trait for usage examples.
4139
@@ -50,9 +48,8 @@ use marker::Sized;
5048///
5149/// [book]: ../../book/borrow-and-asref.html
5250///
53- /// **Note:** these traits are for trivial conversion. **They must not fail**. If
54- /// they can fail, use a dedicated method which return an `Option<T>` or
55- /// a `Result<T, E>`.
51+ /// **Note: this trait must not fail**. If the conversion can fail, use a dedicated method which
52+ /// return an `Option<T>` or a `Result<T, E>`.
5653///
5754/// # Examples
5855///
@@ -73,7 +70,7 @@ use marker::Sized;
7370/// # Generic Impls
7471///
7572/// - `AsRef` auto-dereference if the inner type is a reference or a mutable
76- /// reference
73+ /// reference (eg: `foo.as_ref()` will work the same if `foo` has type `&mut Foo` or `&&mut Foo`)
7774///
7875#[ stable( feature = "rust1" , since = "1.0.0" ) ]
7976pub trait AsRef < T : ?Sized > {
@@ -84,14 +81,13 @@ pub trait AsRef<T: ?Sized> {
8481
8582/// A cheap, mutable reference-to-mutable reference conversion.
8683///
87- /// **Note:** these traits are for trivial conversion. **They must not fail**. If
88- /// they can fail, use a dedicated method which return an `Option<T>` or
89- /// a `Result<T, E>`.
84+ /// **Note: this trait must not fail**. If the conversion can fail, use a dedicated method which
85+ /// return an `Option<T>` or a `Result<T, E>`.
9086///
9187/// # Generic Impls
9288///
9389/// - `AsMut` auto-dereference if the inner type is a reference or a mutable
94- /// reference
90+ /// reference (eg: `foo.as_ref()` will work the same if `foo` has type `&mut Foo` or `&&mut Foo`)
9591///
9692#[ stable( feature = "rust1" , since = "1.0.0" ) ]
9793pub trait AsMut < T : ?Sized > {
@@ -102,9 +98,12 @@ pub trait AsMut<T: ?Sized> {
10298
10399/// A conversion that consumes `self`, which may or may not be expensive.
104100///
105- /// **Note:** these traits are for trivial conversion. **They must not fail**. If
106- /// they can fail, use a dedicated method which return an `Option<T>` or
107- /// a `Result<T, E>`.
101+ /// **Note: this trait must not fail**. If the conversion can fail, use a dedicated method which
102+ /// return an `Option<T>` or a `Result<T, E>`.
103+ ///
104+ /// Library writer should not implement directly this trait, but should prefer the implementation
105+ /// of the `From` trait, which offer greater flexibility and provide the equivalent `Into`
106+ /// implementation for free thanks to a blanket implementation in the standard library.
108107///
109108/// # Examples
110109///
@@ -134,9 +133,8 @@ pub trait Into<T>: Sized {
134133
135134/// Construct `Self` via a conversion.
136135///
137- /// **Note:** these traits are for trivial conversion. **They must not fail**. If
138- /// they can fail, use a dedicated method which return an `Option<T>` or
139- /// a `Result<T, E>`.
136+ /// **Note: this trait must not fail**. If the conversion can fail, use a dedicated method which
137+ /// return an `Option<T>` or a `Result<T, E>`.
140138///
141139/// # Examples
142140///
0 commit comments