@@ -104,7 +104,6 @@ pub const fn identity<T>(x: T) -> T { x }
104
104
/// If you need to do a costly conversion it is better to implement [`From`] with type
105
105
/// `&T` or write a custom function.
106
106
///
107
- ///
108
107
/// `AsRef` has the same signature as [`Borrow`], but `Borrow` is different in few aspects:
109
108
///
110
109
/// - Unlike `AsRef`, `Borrow` has a blanket impl for any `T`, and can be used to accept either
@@ -133,7 +132,7 @@ pub const fn identity<T>(x: T) -> T { x }
133
132
/// converted a the specified type `T`.
134
133
///
135
134
/// For example: By creating a generic function that takes an `AsRef<str>` we express that we
136
- /// want to accept all references that can be converted to &str as an argument.
135
+ /// want to accept all references that can be converted to ` &str` as an argument.
137
136
/// Since both [`String`] and `&str` implement `AsRef<str>` we can accept both as input argument.
138
137
///
139
138
/// [`String`]: ../../std/string/struct.String.html
@@ -149,7 +148,6 @@ pub const fn identity<T>(x: T) -> T { x }
149
148
/// let s = "hello".to_string();
150
149
/// is_hello(s);
151
150
/// ```
152
- ///
153
151
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
154
152
pub trait AsRef < T : ?Sized > {
155
153
/// Performs the conversion.
@@ -182,6 +180,7 @@ pub trait AsRef<T: ?Sized> {
182
180
/// write a function `add_one`that takes all arguments that can be converted to `&mut u64`.
183
181
/// Because [`Box<T>`] implements `AsMut<T>` `add_one` accepts arguments of type
184
182
/// `&mut Box<u64>` as well:
183
+ ///
185
184
/// ```
186
185
/// fn add_one<T: AsMut<u64>>(num: &mut T) {
187
186
/// *num.as_mut() += 1;
@@ -191,8 +190,8 @@ pub trait AsRef<T: ?Sized> {
191
190
/// add_one(&mut boxed_num);
192
191
/// assert_eq!(*boxed_num, 1);
193
192
/// ```
194
- /// [`Box<T>`]: ../../std/boxed/struct.Box.html
195
193
///
194
+ /// [`Box<T>`]: ../../std/boxed/struct.Box.html
196
195
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
197
196
pub trait AsMut < T : ?Sized > {
198
197
/// Performs the conversion.
@@ -203,18 +202,18 @@ pub trait AsMut<T: ?Sized> {
203
202
/// A value-to-value conversion that consumes the input value. The
204
203
/// opposite of [`From`].
205
204
///
206
- /// One should only implement [ `Into`] if a conversion to a type outside the current crate is
207
- /// required. Otherwise one should always prefer implementing [`From`] over [ `Into`] because
208
- /// implementing [`From`] automatically provides one with a implementation of [ `Into`] thanks to
205
+ /// One should only implement `Into` if a conversion to a type outside the current crate is
206
+ /// required. Otherwise one should always prefer implementing [`From`] over `Into` because
207
+ /// implementing [`From`] automatically provides one with a implementation of `Into` thanks to
209
208
/// the blanket implementation in the standard library. [`From`] cannot do these type of
210
209
/// conversions because of Rust's orphaning rules.
211
210
///
212
211
/// **Note: This trait must not fail**. If the conversion can fail, use [`TryInto`].
213
212
///
214
213
/// # Generic Implementations
215
214
///
216
- /// - [`From<T> `]` for U` implies `Into<U> for T`
217
- /// - [ `Into`] ` is reflexive, which means that `Into<T> for T` is implemented
215
+ /// - [`From`]`<T> for U` implies `Into<U> for T`
216
+ /// - `Into` is reflexive, which means that `Into<T> for T` is implemented
218
217
///
219
218
/// # Implementing `Into` for conversions to external types
220
219
///
@@ -273,7 +272,7 @@ pub trait AsMut<T: ?Sized> {
273
272
/// [`Option<T>`]: ../../std/option/enum.Option.html
274
273
/// [`Result<T, E>`]: ../../std/result/enum.Result.html
275
274
/// [`String`]: ../../std/string/struct.String.html
276
- /// [From]: trait.From.html
275
+ /// [` From` ]: trait.From.html
277
276
/// [`into`]: trait.Into.html#tymethod.into
278
277
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
279
278
pub trait Into < T > : Sized {
@@ -285,18 +284,18 @@ pub trait Into<T>: Sized {
285
284
/// Used to do value-to-value conversions while consuming the input value. It is the reciprocal of
286
285
/// [`Into`].
287
286
///
288
- /// One should always prefer implementing [ `From`] over [`Into`]
289
- /// because implementing [ `From`] automatically provides one with a implementation of [`Into`]
287
+ /// One should always prefer implementing `From` over [`Into`]
288
+ /// because implementing `From` automatically provides one with a implementation of [`Into`]
290
289
/// thanks to the blanket implementation in the standard library.
291
290
///
292
291
/// Only implement [`Into`] if a conversion to a type outside the current crate is required.
293
- /// [ `From`] cannot do these type of conversions because of Rust's orphaning rules.
292
+ /// `From` cannot do these type of conversions because of Rust's orphaning rules.
294
293
/// See [`Into`] for more details.
295
294
///
296
- /// Prefer using [`Into`] over using [ `From`] when specifying trait bounds on a generic function.
295
+ /// Prefer using [`Into`] over using `From` when specifying trait bounds on a generic function.
297
296
/// This way, types that directly implement [`Into`] can be used as arguments as well.
298
297
///
299
- /// The [ `From`] is also very useful when performing error handling. When constructing a function
298
+ /// The `From` is also very useful when performing error handling. When constructing a function
300
299
/// that is capable of failing, the return type will generally be of the form `Result<T, E>`.
301
300
/// The `From` trait simplifies error handling by allowing a function to return a single error type
302
301
/// that encapsulate multiple error types. See the "Examples" section and [the book][book] for more
@@ -306,14 +305,15 @@ pub trait Into<T>: Sized {
306
305
///
307
306
/// # Generic Implementations
308
307
///
309
- /// - [ `From<T>`]` for U` implies [`Into<U> `]` for T`
310
- /// - [ `From`] is reflexive, which means that `From<T> for T` is implemented
308
+ /// - `From<T> for U` implies [`Into`]`<U> for T`
309
+ /// - `From` is reflexive, which means that `From<T> for T` is implemented
311
310
///
312
311
/// # Examples
313
312
///
314
313
/// [`String`] implements `From<&str>`:
315
314
///
316
- /// An explicit conversion from a &str to a String is done as follows:
315
+ /// An explicit conversion from a `&str` to a String is done as follows:
316
+ ///
317
317
/// ```
318
318
/// let string = "hello".to_string();
319
319
/// let other_string = String::from("hello");
@@ -361,7 +361,7 @@ pub trait Into<T>: Sized {
361
361
/// [`Option<T>`]: ../../std/option/enum.Option.html
362
362
/// [`Result<T, E>`]: ../../std/result/enum.Result.html
363
363
/// [`String`]: ../../std/string/struct.String.html
364
- /// [`Into<U> `]: trait.Into.html
364
+ /// [`Into`]: trait.Into.html
365
365
/// [`from`]: trait.From.html#tymethod.from
366
366
/// [book]: ../../book/ch09-00-error-handling.html
367
367
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -422,7 +422,7 @@ pub trait TryInto<T>: Sized {
422
422
///
423
423
/// # Generic Implementations
424
424
///
425
- /// - `TryFrom<T> for U` implies [`TryInto<U> `]` for T`
425
+ /// - `TryFrom<T> for U` implies [`TryInto`]`<U> for T`
426
426
/// - [`try_from`] is reflexive, which means that `TryFrom<T> for T`
427
427
/// is implemented and cannot fail -- the associated `Error` type for
428
428
/// calling `T::try_from()` on a value of type `T` is `Infallible`.
0 commit comments