@@ -165,7 +165,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
165
165
/// # Example
166
166
///
167
167
/// ```
168
- /// let x: &[u8] = ['f' as u8, 'o' as u8, 'o' as u8, 0] ;
168
+ /// let x: &[u8] = b"foo\0" ;
169
169
/// assert!(Path::new_opt(x).is_none());
170
170
/// ```
171
171
#[ inline]
@@ -197,7 +197,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
197
197
///
198
198
/// ```
199
199
/// let p = Path::new("abc/def");
200
- /// assert_eq!(p.as_vec(), &[97, 98, 99, 47, 100, 101, 102] );
200
+ /// assert_eq!(p.as_vec(), b"abc/def" );
201
201
/// ```
202
202
fn as_vec < ' a > ( & ' a self ) -> & ' a [ u8 ] ;
203
203
@@ -207,7 +207,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
207
207
///
208
208
/// ```
209
209
/// let p = Path::new("abc/def");
210
- /// assert_eq!(p.into_vec(), vec!(97, 98, 99, 47, 100, 101, 102 ));
210
+ /// assert_eq!(p.into_vec(), b"abc/def".to_vec( ));
211
211
/// // attempting to use p now results in "error: use of moved value"
212
212
/// ```
213
213
fn into_vec ( self ) -> Vec < u8 > ;
@@ -245,7 +245,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
245
245
///
246
246
/// ```
247
247
/// let p = Path::new("abc/def/ghi");
248
- /// assert_eq!(p.dirname(), &[97, 98, 99, 47, 100, 101, 102] );
248
+ /// assert_eq!(p.dirname(), b"abc/def" );
249
249
/// ```
250
250
fn dirname < ' a > ( & ' a self ) -> & ' a [ u8 ] ;
251
251
@@ -271,7 +271,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
271
271
///
272
272
/// ```
273
273
/// let p = Path::new("abc/def/ghi");
274
- /// assert_eq!(p.filename(), Some(&[103, 104, 105] ));
274
+ /// assert_eq!(p.filename(), Some(b"ghi" ));
275
275
/// ```
276
276
fn filename < ' a > ( & ' a self ) -> Option < & ' a [ u8 ] > ;
277
277
@@ -297,7 +297,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
297
297
///
298
298
/// ```
299
299
/// let p = Path::new("/abc/def.txt");
300
- /// assert_eq!(p.filestem(), Some(&[100, 101, 102] ));
300
+ /// assert_eq!(p.filestem(), Some(b"def" ));
301
301
/// ```
302
302
fn filestem < ' a > ( & ' a self ) -> Option < & ' a [ u8 ] > {
303
303
match self . filename ( ) {
@@ -336,7 +336,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
336
336
///
337
337
/// ```
338
338
/// let p = Path::new("abc/def.txt");
339
- /// assert_eq!(p.extension(), Some(&[116, 120, 116] ));
339
+ /// assert_eq!(p.extension(), Some(b"txt" ));
340
340
/// ```
341
341
fn extension < ' a > ( & ' a self ) -> Option < & ' a [ u8 ] > {
342
342
match self . filename ( ) {
@@ -458,6 +458,13 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
458
458
/// byte vector or string.
459
459
/// See `set_extension` for details.
460
460
///
461
+ /// # Example
462
+ ///
463
+ /// ```
464
+ /// let mut p = Path::new("abc/def.txt");
465
+ /// assert!(p.with_extension("csv") == Path::new("abc/def.csv"));
466
+ /// ```
467
+ ///
461
468
/// # Failure
462
469
///
463
470
/// Fails the task if the extension contains a NUL.
0 commit comments