42
42
43
43
/// A cheap, reference-to-reference conversion.
44
44
///
45
- /// `AsRef` is very similar to, but different than, `Borrow`. See
45
+ /// `AsRef` is very similar to, but different than, [ `Borrow`] . See
46
46
/// [the book][book] for more.
47
47
///
48
48
/// [book]: ../../book/borrow-and-asref.html
49
+ /// [`Borrow`]: ../../std/borrow/trait.Borrow.html
49
50
///
50
51
/// **Note: this trait must not fail**. If the conversion can fail, use a dedicated method which
51
- /// returns an `Option<T>` or a `Result<T, E>`.
52
+ /// returns an [`Option<T>`] or a [`Result<T, E>`].
53
+ ///
54
+ /// [`Option<T>`]: ../../std/option/enum.Option.html
55
+ /// [`Result<T, E>`]: ../../std/result/enum.Result.html
52
56
///
53
57
/// # Examples
54
58
///
55
- /// Both `String` and `&str` implement `AsRef<str>`:
59
+ /// Both [`String`] and `&str` implement `AsRef<str>`:
60
+ ///
61
+ /// [`String`]: ../../std/string/struct.String.html
56
62
///
57
63
/// ```
58
64
/// fn is_hello<T: AsRef<str>>(s: T) {
@@ -81,7 +87,10 @@ pub trait AsRef<T: ?Sized> {
81
87
/// A cheap, mutable reference-to-mutable reference conversion.
82
88
///
83
89
/// **Note: this trait must not fail**. If the conversion can fail, use a dedicated method which
84
- /// returns an `Option<T>` or a `Result<T, E>`.
90
+ /// returns an [`Option<T>`] or a [`Result<T, E>`].
91
+ ///
92
+ /// [`Option<T>`]: ../../std/option/enum.Option.html
93
+ /// [`Result<T, E>`]: ../../std/result/enum.Result.html
85
94
///
86
95
/// # Generic Impls
87
96
///
@@ -97,16 +106,16 @@ pub trait AsMut<T: ?Sized> {
97
106
98
107
/// A conversion that consumes `self`, which may or may not be expensive.
99
108
///
100
- /// **Note: this trait must not fail**. If the conversion can fail, use `TryInto` or a dedicated
101
- /// method which returns an `Option<T>` or a `Result<T, E>`.
109
+ /// **Note: this trait must not fail**. If the conversion can fail, use [ `TryInto`] or a dedicated
110
+ /// method which returns an [ `Option<T>`] or a [ `Result<T, E>`] .
102
111
///
103
112
/// Library authors should not directly implement this trait, but should prefer implementing
104
- /// the `From` trait, which offers greater flexibility and provides an equivalent `Into`
113
+ /// the [ `From`][From] trait, which offers greater flexibility and provides an equivalent `Into`
105
114
/// implementation for free, thanks to a blanket implementation in the standard library.
106
115
///
107
116
/// # Examples
108
117
///
109
- /// `String` implements `Into<Vec<u8>>`:
118
+ /// [ `String`] implements `Into<Vec<u8>>`:
110
119
///
111
120
/// ```
112
121
/// fn is_hello<T: Into<Vec<u8>>>(s: T) {
@@ -120,9 +129,15 @@ pub trait AsMut<T: ?Sized> {
120
129
///
121
130
/// # Generic Impls
122
131
///
123
- /// - `From<T> for U` implies `Into<U> for T`
124
- /// - `into()` is reflexive, which means that `Into<T> for T` is implemented
132
+ /// - `[ From<T>][From] for U` implies `Into<U> for T`
133
+ /// - [ `into()`] is reflexive, which means that `Into<T> for T` is implemented
125
134
///
135
+ /// [`TryInto`]: trait.TryInto.html
136
+ /// [`Option<T>`]: ../../std/option/enum.Option.html
137
+ /// [`Result<T, E>`]: ../../std/result/enum.Result.html
138
+ /// [`String`]: ../../std/string/struct.String.html
139
+ /// [From]: trait.From.html
140
+ /// [`into()`]: trait.Into.html#tymethod.into
126
141
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
127
142
pub trait Into < T > : Sized {
128
143
/// Performs the conversion.
@@ -132,12 +147,12 @@ pub trait Into<T>: Sized {
132
147
133
148
/// Construct `Self` via a conversion.
134
149
///
135
- /// **Note: this trait must not fail**. If the conversion can fail, use `TryFrom` or a dedicated
136
- /// method which returns an `Option<T>` or a `Result<T, E>`.
150
+ /// **Note: this trait must not fail**. If the conversion can fail, use [ `TryFrom`] or a dedicated
151
+ /// method which returns an [ `Option<T>`] or a [ `Result<T, E>`] .
137
152
///
138
153
/// # Examples
139
154
///
140
- /// `String` implements `From<&str>`:
155
+ /// [ `String`] implements `From<&str>`:
141
156
///
142
157
/// ```
143
158
/// let string = "hello".to_string();
@@ -147,9 +162,15 @@ pub trait Into<T>: Sized {
147
162
/// ```
148
163
/// # Generic impls
149
164
///
150
- /// - `From<T> for U` implies `Into<U> for T`
151
- /// - `from()` is reflexive, which means that `From<T> for T` is implemented
165
+ /// - `From<T> for U` implies `[ Into<U>] for T`
166
+ /// - [ `from()`] is reflexive, which means that `From<T> for T` is implemented
152
167
///
168
+ /// [`TryFrom`]: trait.TryFrom.html
169
+ /// [`Option<T>`]: ../../std/option/enum.Option.html
170
+ /// [`Result<T, E>`]: ../../std/result/enum.Result.html
171
+ /// [`String`]: ../../std/string/struct.String.html
172
+ /// [Into<U>]: trait.Into.html
173
+ /// [`from()`]: trait.From.html#tymethod.from
153
174
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
154
175
pub trait From < T > : Sized {
155
176
/// Performs the conversion.
@@ -160,8 +181,10 @@ pub trait From<T>: Sized {
160
181
/// An attempted conversion that consumes `self`, which may or may not be expensive.
161
182
///
162
183
/// Library authors should not directly implement this trait, but should prefer implementing
163
- /// the `TryFrom` trait, which offers greater flexibility and provides an equivalent `TryInto`
184
+ /// the [ `TryFrom`] trait, which offers greater flexibility and provides an equivalent `TryInto`
164
185
/// implementation for free, thanks to a blanket implementation in the standard library.
186
+ ///
187
+ /// [`TryFrom`]: trait.TryFrom.html
165
188
#[ unstable( feature = "try_from" , issue = "33417" ) ]
166
189
pub trait TryInto < T > : Sized {
167
190
/// The type returned in the event of a conversion error.
0 commit comments