Skip to content

Commit 79efca1

Browse files
committed
Wrapped to 80 characters. Fix links.
1 parent 7897e16 commit 79efca1

File tree

1 file changed

+58
-40
lines changed

1 file changed

+58
-40
lines changed

src/libcore/convert.rs

+58-40
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@
2626
//! As a library author, you should prefer implementing [`From<T>`][`From`] or
2727
//! [`TryFrom<T>`][`TryFrom`] rather than [`Into<U>`][`Into`] or [`TryInto<U>`][`TryInto`],
2828
//! as [`From`] and [`TryFrom`] provide greater flexibility and offer
29-
//! equivalent [`Into`] or [`TryInto`] implementations for free, thanks to a blanket implementation
30-
//! in the standard library.
29+
//! equivalent [`Into`] or [`TryInto`] implementations for free, thanks to a
30+
//! blanket implementation in the standard library.
3131
//!
3232
//! # Generic Implementations
3333
//!
3434
//! - [`AsRef`] and [`AsMut`] auto-dereference if the inner type is a reference
3535
//! - [`From`]`<U> for T` implies [`Into`]`<T> for U`
3636
//! - [`TryFrom`]`<U> for T` implies [`TryInto`]`<T> for U`
37-
//! - [`From`] and [`Into`] are reflexive, which means that all types can `into()`
38-
//! themselves and `from()` themselves
37+
//! - [`From`] and [`Into`] are reflexive, which means that all types can
38+
//! `into()` themselves and `from()` themselves
3939
//!
4040
//! See each trait for usage examples.
4141
//!
@@ -50,39 +50,45 @@
5050

5151
use str::FromStr;
5252

53-
/// A cheap reference-to-reference conversion. Used to convert a value to a reference value
54-
/// within generic code.
55-
///
56-
/// `AsRef` is very similar to, but serves a slightly different purpose than, [`Borrow`].
57-
///
58-
/// `AsRef` is to be used when wishing to convert to a reference of another type.
59-
/// `Borrow` is more related to the notion of taking the reference. It is useful when wishing to abstract
60-
/// over the type of reference (`&T`, `&mut T`) or allow both the referenced and owned type to be treated in the same manner.
53+
/// A cheap reference-to-reference conversion. Used to convert a value to a
54+
/// reference value within generic code.
55+
///
56+
/// `AsRef` is very similar to, but serves a slightly different purpose than,
57+
/// [`Borrow`].
58+
///
59+
/// `AsRef` is to be used when wishing to convert to a reference of another
60+
/// type.
61+
/// `Borrow` is more related to the notion of taking the reference. It is
62+
/// useful when wishing to abstract
63+
/// over the type of reference (`&T`, `&mut T`) or allow both the referenced
64+
/// and owned type to be treated in the same manner.
6165
/// The key difference between the two traits is the intention:
6266
///
6367
/// - Use `AsRef` when goal is to simply convert into a reference
64-
/// - Use `Borrow` when goal is related to writing code that is agnostic to the type of borrow and if is reference or value
68+
/// - Use `Borrow` when goal is related to writing code that is agnostic to the
69+
/// type of borrow and if is reference or value
6570
///
6671
/// See [the book][book] for a more detailed comparison.
6772
///
6873
/// [book]: ../../book/borrow-and-asref.html
6974
/// [`Borrow`]: ../../std/borrow/trait.Borrow.html
7075
///
71-
/// **Note: this trait must not fail**. If the conversion can fail, use a dedicated method which
72-
/// returns an [`Option<T>`] or a [`Result<T, E>`].
76+
/// **Note: this trait must not fail**. If the conversion can fail, use a
77+
/// dedicated method which returns an [`Option<T>`] or a [`Result<T, E>`].
7378
///
7479
/// [`Option<T>`]: ../../std/option/enum.Option.html
7580
/// [`Result<T, E>`]: ../../std/result/enum.Result.html
7681
///
7782
/// # Generic Implementations
7883
///
7984
/// - `AsRef` auto-dereferences if the inner type is a reference or a mutable
80-
/// reference (e.g.: `foo.as_ref()` will work the same if `foo` has type `&mut Foo` or `&&mut Foo`)
85+
/// reference (e.g.: `foo.as_ref()` will work the same if `foo` has type
86+
/// `&mut Foo` or `&&mut Foo`)
8187
///
8288
/// # Examples
8389
/// An example implementation of the trait is [`Path`].
8490
///
85-
/// [`Path`]: ../../std/struct.Path.html
91+
/// [`Path`]: ../../std/path/struct.Path.html
8692
///
8793
/// ```
8894
/// impl AsRef<Path> for str {
@@ -119,16 +125,17 @@ pub trait AsRef<T: ?Sized> {
119125
///
120126
/// This trait is similar to `AsRef` but used for converting mutable references.
121127
///
122-
/// **Note: this trait must not fail**. If the conversion can fail, use a dedicated method which
123-
/// returns an [`Option<T>`] or a [`Result<T, E>`].
128+
/// **Note: this trait must not fail**. If the conversion can fail, use a
129+
/// dedicated method which returns an [`Option<T>`] or a [`Result<T, E>`].
124130
///
125131
/// [`Option<T>`]: ../../std/option/enum.Option.html
126132
/// [`Result<T, E>`]: ../../std/result/enum.Result.html
127133
///
128134
/// # Generic Implementations
129135
///
130136
/// - `AsMut` auto-dereferences if the inner type is a reference or a mutable
131-
/// reference (e.g.: `foo.as_ref()` will work the same if `foo` has type `&mut Foo` or `&&mut Foo`)
137+
/// reference (e.g.: `foo.as_ref()` will work the same if `foo` has type
138+
/// `&mut Foo` or `&&mut Foo`)
132139
///
133140
/// # Examples
134141
///
@@ -161,14 +168,17 @@ pub trait AsMut<T: ?Sized> {
161168
fn as_mut(&mut self) -> &mut T;
162169
}
163170

164-
/// A conversion that consumes `self`, which may or may not be expensive. The reciprocal of [`From`][From].
171+
/// A conversion that consumes `self`, which may or may not be expensive. The
172+
/// reciprocal of [`From`][From].
165173
///
166-
/// **Note: this trait must not fail**. If the conversion can fail, use [`TryInto`] or a dedicated
167-
/// method which returns an [`Option<T>`] or a [`Result<T, E>`].
174+
/// **Note: this trait must not fail**. If the conversion can fail, use
175+
/// [`TryInto`] or a dedicated method which returns an [`Option<T>`] or a
176+
/// [`Result<T, E>`].
168177
///
169-
/// Library authors should not directly implement this trait, but should prefer implementing
170-
/// the [`From`][From] trait, which offers greater flexibility and provides an equivalent `Into`
171-
/// implementation for free, thanks to a blanket implementation in the standard library.
178+
/// Library authors should not directly implement this trait, but should prefer
179+
/// implementing the [`From`][From] trait, which offers greater flexibility and
180+
/// provides an equivalent `Into` implementation for free, thanks to a blanket
181+
/// implementation in the standard library.
172182
///
173183
/// # Generic Implementations
174184
///
@@ -202,18 +212,24 @@ pub trait Into<T>: Sized {
202212
fn into(self) -> T;
203213
}
204214

205-
/// Simple and safe type conversions in to `Self`. It is the reciprocal of `Into`.
215+
/// Simple and safe type conversions in to `Self`. It is the reciprocal of
216+
/// `Into`.
206217
///
207-
/// This trait is useful when performing error handling as described by [the book][book] and is closely related to the `?` operator.
218+
/// This trait is useful when performing error handling as described by
219+
/// [the book][book] and is closely related to the `?` operator.
208220
///
209-
/// When constructing a function that is capable of failing the return type will generally be of the form `Result<T, E>`.
210-
/// The `From` trait allows for simplification of error handling by providing a means of returning a single error type that encapsulates
211-
/// numerous possible erroneous situations.
212-
/// This trait is not limited to error handling, rather the general case for this trait would be in any type conversions to have an
213-
/// explicit definition of how they are performed.
221+
/// When constructing a function that is capable of failing the return type
222+
/// will generally be of the form `Result<T, E>`.
223+
/// The `From` trait allows for simplification of error handling by providing a
224+
/// means of returning a single error type that encapsulates numerous possible
225+
/// erroneous situations.
226+
/// This trait is not limited to error handling, rather the general case for
227+
/// this trait would be in any type conversions to have an explicit definition
228+
/// of how they are performed.
214229
///
215-
/// **Note: this trait must not fail**. If the conversion can fail, use [`TryFrom`] or a dedicated
216-
/// method which returns an [`Option<T>`] or a [`Result<T, E>`].
230+
/// **Note: this trait must not fail**. If the conversion can fail, use
231+
/// [`TryFrom`] or a dedicated method which returns an [`Option<T>`] or a
232+
/// [`Result<T, E>`].
217233
///
218234
/// # Generic Implementations
219235
///
@@ -265,19 +281,21 @@ pub trait Into<T>: Sized {
265281
/// [`String`]: ../../std/string/struct.String.html
266282
/// [`Into<U>`]: trait.Into.html
267283
/// [`from`]: trait.From.html#tymethod.from
268-
/// [book]: ../../book/error-handling.html#the-from-trait
284+
/// [book]: ../../book/error-handling.html
269285
#[stable(feature = "rust1", since = "1.0.0")]
270286
pub trait From<T>: Sized {
271287
/// Performs the conversion.
272288
#[stable(feature = "rust1", since = "1.0.0")]
273289
fn from(T) -> Self;
274290
}
275291

276-
/// An attempted conversion that consumes `self`, which may or may not be expensive.
292+
/// An attempted conversion that consumes `self`, which may or may not be
293+
/// expensive.
277294
///
278-
/// Library authors should not directly implement this trait, but should prefer implementing
279-
/// the [`TryFrom`] trait, which offers greater flexibility and provides an equivalent `TryInto`
280-
/// implementation for free, thanks to a blanket implementation in the standard library.
295+
/// Library authors should not directly implement this trait, but should prefer
296+
/// implementing the [`TryFrom`] trait, which offers greater flexibility and
297+
/// provides an equivalent `TryInto` implementation for free, thanks to a
298+
/// blanket implementation in the standard library.
281299
///
282300
/// [`TryFrom`]: trait.TryFrom.html
283301
#[unstable(feature = "try_from", issue = "33417")]

0 commit comments

Comments
 (0)