66//! - Implement the [`AsRef`] trait for cheap reference-to-reference conversions
77//! - Implement the [`AsMut`] trait for cheap mutable-to-mutable conversions
88//! - Implement the [`From`] trait for consuming value-to-value conversions
9- //! - Implement the [`Into`] trait for consuming value-to-value conversions to types outside the current crate
10- //! - The [`TryFrom`] and [`TryInto`] traits behave like [`From`] and [`Into`], but should be implemented when
9+ //! - Implement the [`Into`] trait for consuming value-to-value conversions to types
10+ //! outside the current crate
11+ //! - The [`TryFrom`] and [`TryInto`] traits behave like [`From`] and [`Into`],
12+ //! but should be implemented when
1113//! the conversion can fail.
1214//!
1315//! The traits in this module are often used as trait bounds for generic functions such that to
@@ -196,9 +198,10 @@ pub trait AsMut<T: ?Sized> {
196198/// A value-to-value conversion that consumes the input value. The
197199/// opposite of [`From`].
198200///
199- /// One should only implement [`Into`] if a conversion to a type outside the current crate is required.
200- /// Otherwise one should always prefer implementing [`From`] over [`Into`] because implementing [`From`] automatically
201- /// provides one with a implementation of [`Into`] thanks to the blanket implementation in the standard library.
201+ /// One should only implement [`Into`] if a conversion to a type outside the current crate is
202+ /// required. Otherwise one should always prefer implementing [`From`] over [`Into`] because
203+ /// implementing [`From`] automatically provides one with a implementation of [`Into`]
204+ /// thanks to the blanket implementation in the standard library.
202205/// [`From`] cannot do these type of conversions because of Rust's orphaning rules.
203206///
204207/// **Note: This trait must not fail**. If the conversion can fail, use [`TryInto`].
@@ -209,7 +212,8 @@ pub trait AsMut<T: ?Sized> {
209212/// - [`Into`]` is reflexive, which means that `Into<T> for T` is implemented
210213///
211214/// # Implementing `Into` for conversions to external types
212- /// If the destination type is not part of the current crate then you can't implement [`From`] directly.
215+ /// If the destination type is not part of the current crate
216+ /// then you can't implement [`From`] directly.
213217/// For example, take this code:
214218///
215219/// ```compile_fail
@@ -233,8 +237,9 @@ pub trait AsMut<T: ?Sized> {
233237/// }
234238/// ```
235239///
236- /// It is important to understand that ```Into``` does not provide a [`From`] implementation (as [`From`] does with ```Into```).
237- /// Therefore, you should always try to implement [`From`] and then fall back to `Into` if [`From`] can't be implemented.
240+ /// It is important to understand that ```Into``` does not provide a [`From`] implementation
241+ /// (as [`From`] does with ```Into```). Therefore, you should always try to implement [`From`]
242+ /// and then fall back to `Into` if [`From`] can't be implemented.
238243/// Prefer using ```Into``` over ```From``` when specifying trait bounds on a generic function
239244/// to ensure that types that only implement ```Into``` can be used as well.
240245///
@@ -274,8 +279,9 @@ pub trait Into<T>: Sized {
274279/// Used to do value-to-value conversions while consuming the input value. It is the reciprocal of
275280/// [`Into`].
276281///
277- /// One should always prefer implementing [`From`] over [`Into`] because implementing [`From`] automatically
278- /// provides one with a implementation of [`Into`] thanks to the blanket implementation in the standard library.
282+ /// One should always prefer implementing [`From`] over [`Into`]
283+ /// because implementing [`From`] automatically provides one with a implementation of [`Into`]
284+ /// thanks to the blanket implementation in the standard library.
279285/// Only implement [`Into`] if a conversion to a type outside the current crate is required.
280286/// [`From`] cannot do these type of conversions because of Rust's orphaning rules.
281287/// See [`Into`] for more details.
@@ -308,11 +314,12 @@ pub trait Into<T>: Sized {
308314/// assert_eq!(string, other_string);
309315/// ```
310316///
311- /// While performing error handling it is often useful to implement ```From``` for your own error type.
312- /// By converting underlying error types to our own custom error type that encapsulates the underlying
313- /// error type, we can return a single error type without losing information on the underlying cause.
314- /// The '?' operator automatically converts the underlying error type to our custom error type by
315- /// calling ```Into<CliError>::into``` which is automatically provided when implementing ```From```.
317+ /// While performing error handling it is often useful to implement ```From```
318+ /// for your own error type. By converting underlying error types to our own custom error type
319+ /// that encapsulates the underlying error type, we can return a single error type
320+ /// without losing information on the underlying cause. The '?' operator automatically converts
321+ /// the underlying error type to our custom error type by calling ```Into<CliError>::into```
322+ /// which is automatically provided when implementing ```From```.
316323/// The compiler then infers which implementation of ```Into``` should be used.
317324///
318325/// ```
0 commit comments