Skip to content

Commit a0238d5

Browse files
nhamalexcrichton
authored andcommitted
Use byte strings throughout examples. Add an example that was missed in the last commit.
1 parent 9956aff commit a0238d5

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/libstd/path/mod.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
165165
/// # Example
166166
///
167167
/// ```
168-
/// let x: &[u8] = ['f' as u8, 'o' as u8, 'o' as u8, 0];
168+
/// let x: &[u8] = b"foo\0";
169169
/// assert!(Path::new_opt(x).is_none());
170170
/// ```
171171
#[inline]
@@ -197,7 +197,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
197197
///
198198
/// ```
199199
/// 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");
201201
/// ```
202202
fn as_vec<'a>(&'a self) -> &'a [u8];
203203

@@ -207,7 +207,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
207207
///
208208
/// ```
209209
/// 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());
211211
/// // attempting to use p now results in "error: use of moved value"
212212
/// ```
213213
fn into_vec(self) -> Vec<u8>;
@@ -245,7 +245,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
245245
///
246246
/// ```
247247
/// 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");
249249
/// ```
250250
fn dirname<'a>(&'a self) -> &'a [u8];
251251

@@ -271,7 +271,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
271271
///
272272
/// ```
273273
/// let p = Path::new("abc/def/ghi");
274-
/// assert_eq!(p.filename(), Some(&[103, 104, 105]));
274+
/// assert_eq!(p.filename(), Some(b"ghi"));
275275
/// ```
276276
fn filename<'a>(&'a self) -> Option<&'a [u8]>;
277277

@@ -297,7 +297,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
297297
///
298298
/// ```
299299
/// let p = Path::new("/abc/def.txt");
300-
/// assert_eq!(p.filestem(), Some(&[100, 101, 102]));
300+
/// assert_eq!(p.filestem(), Some(b"def"));
301301
/// ```
302302
fn filestem<'a>(&'a self) -> Option<&'a [u8]> {
303303
match self.filename() {
@@ -336,7 +336,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
336336
///
337337
/// ```
338338
/// let p = Path::new("abc/def.txt");
339-
/// assert_eq!(p.extension(), Some(&[116, 120, 116]));
339+
/// assert_eq!(p.extension(), Some(b"txt"));
340340
/// ```
341341
fn extension<'a>(&'a self) -> Option<&'a [u8]> {
342342
match self.filename() {
@@ -458,6 +458,13 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
458458
/// byte vector or string.
459459
/// See `set_extension` for details.
460460
///
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+
///
461468
/// # Failure
462469
///
463470
/// Fails the task if the extension contains a NUL.

0 commit comments

Comments
 (0)