@@ -91,6 +91,8 @@ use str::FromStr;
91
91
/// [`Path`]: ../../std/path/struct.Path.html
92
92
///
93
93
/// ```
94
+ /// use std::path::Path;
95
+ ///
94
96
/// impl AsRef<Path> for str {
95
97
/// fn as_ref(&self) -> &Path {
96
98
/// Path::new(self)
@@ -123,7 +125,8 @@ pub trait AsRef<T: ?Sized> {
123
125
124
126
/// A cheap, mutable reference-to-mutable reference conversion.
125
127
///
126
- /// This trait is similar to `AsRef` but used for converting mutable references.
128
+ /// This trait is similar to `AsRef` but used for converting between mutable
129
+ /// references.
127
130
///
128
131
/// **Note: this trait must not fail**. If the conversion can fail, use a
129
132
/// dedicated method which returns an [`Option<T>`] or a [`Result<T, E>`].
@@ -153,11 +156,13 @@ pub trait AsRef<T: ?Sized> {
153
156
/// assert_eq!(*boxed_num, 1);
154
157
/// ```
155
158
///
156
- /// Implementing `AsMut`:
159
+ /// `Vec` implements `AsMut` for converting between itself and a primitive array :
157
160
///
158
161
/// ```
159
- /// impl Type {
160
- /// let a = 1;
162
+ /// impl<T> AsMut<[T]> for Vec<T> {
163
+ /// fn as_mut(&mut self) -> &mut [T] {
164
+ /// self
165
+ /// }
161
166
/// }
162
167
/// ```
163
168
///
@@ -250,19 +255,22 @@ pub trait Into<T>: Sized {
250
255
/// An example usage for error handling:
251
256
///
252
257
/// ```
258
+ /// use std::io::{self, Read};
259
+ /// use std::num;
260
+ ///
253
261
/// enum CliError {
254
262
/// IoError(io::Error),
255
263
/// ParseError(num::ParseIntError),
256
264
/// }
257
265
///
258
- /// impl From<io::Error> for MyError {
266
+ /// impl From<io::Error> for CliError {
259
267
/// fn from(error: io::Error) -> Self {
260
268
/// CliError::IoError(error)
261
269
/// }
262
270
/// }
263
271
///
264
- /// impl From<num::ParseIntError> for MyError {
265
- /// fn from(error: io::Error ) -> Self {
272
+ /// impl From<num::ParseIntError> for CliError {
273
+ /// fn from(error: num::ParseIntError ) -> Self {
266
274
/// CliError::ParseError(error)
267
275
/// }
268
276
/// }
0 commit comments