From a0238d54aac73491a7b691cc8c797b23de09439c Mon Sep 17 00:00:00 2001 From: nham Date: Wed, 30 Jul 2014 14:19:47 -0400 Subject: [PATCH] Use byte strings throughout examples. Add an example that was missed in the last commit. --- src/libstd/path/mod.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 25367dd53f4..7ce6e9b7049 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -165,7 +165,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Example /// /// ``` - /// let x: &[u8] = ['f' as u8, 'o' as u8, 'o' as u8, 0]; + /// let x: &[u8] = b"foo\0"; /// assert!(Path::new_opt(x).is_none()); /// ``` #[inline] @@ -197,7 +197,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// /// ``` /// let p = Path::new("abc/def"); - /// assert_eq!(p.as_vec(), &[97, 98, 99, 47, 100, 101, 102]); + /// assert_eq!(p.as_vec(), b"abc/def"); /// ``` fn as_vec<'a>(&'a self) -> &'a [u8]; @@ -207,7 +207,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// /// ``` /// let p = Path::new("abc/def"); - /// assert_eq!(p.into_vec(), vec!(97, 98, 99, 47, 100, 101, 102)); + /// assert_eq!(p.into_vec(), b"abc/def".to_vec()); /// // attempting to use p now results in "error: use of moved value" /// ``` fn into_vec(self) -> Vec; @@ -245,7 +245,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// /// ``` /// let p = Path::new("abc/def/ghi"); - /// assert_eq!(p.dirname(), &[97, 98, 99, 47, 100, 101, 102]); + /// assert_eq!(p.dirname(), b"abc/def"); /// ``` fn dirname<'a>(&'a self) -> &'a [u8]; @@ -271,7 +271,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// /// ``` /// let p = Path::new("abc/def/ghi"); - /// assert_eq!(p.filename(), Some(&[103, 104, 105])); + /// assert_eq!(p.filename(), Some(b"ghi")); /// ``` fn filename<'a>(&'a self) -> Option<&'a [u8]>; @@ -297,7 +297,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// /// ``` /// let p = Path::new("/abc/def.txt"); - /// assert_eq!(p.filestem(), Some(&[100, 101, 102])); + /// assert_eq!(p.filestem(), Some(b"def")); /// ``` fn filestem<'a>(&'a self) -> Option<&'a [u8]> { match self.filename() { @@ -336,7 +336,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// /// ``` /// let p = Path::new("abc/def.txt"); - /// assert_eq!(p.extension(), Some(&[116, 120, 116])); + /// assert_eq!(p.extension(), Some(b"txt")); /// ``` fn extension<'a>(&'a self) -> Option<&'a [u8]> { match self.filename() { @@ -458,6 +458,13 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// byte vector or string. /// See `set_extension` for details. /// + /// # Example + /// + /// ``` + /// let mut p = Path::new("abc/def.txt"); + /// assert!(p.with_extension("csv") == Path::new("abc/def.csv")); + /// ``` + /// /// # Failure /// /// Fails the task if the extension contains a NUL.