Use byte strings throughout examples. Add an example that was missed in the last commit.
This commit is contained in:
parent
9956aff18a
commit
a0238d54aa
@ -165,7 +165,7 @@ fn new<T: BytesContainer>(path: T) -> Self {
|
||||
/// # 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 @@ fn as_str<'a>(&'a self) -> Option<&'a str> {
|
||||
///
|
||||
/// ```
|
||||
/// 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 @@ fn as_str<'a>(&'a self) -> Option<&'a str> {
|
||||
///
|
||||
/// ```
|
||||
/// 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<u8>;
|
||||
@ -245,7 +245,7 @@ fn filename_display<'a>(&'a self) -> Display<'a, Self> {
|
||||
///
|
||||
/// ```
|
||||
/// 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 @@ fn dirname_str<'a>(&'a self) -> Option<&'a str> {
|
||||
///
|
||||
/// ```
|
||||
/// 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 @@ fn filename_str<'a>(&'a self) -> Option<&'a str> {
|
||||
///
|
||||
/// ```
|
||||
/// 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 @@ fn filestem_str<'a>(&'a self) -> Option<&'a str> {
|
||||
///
|
||||
/// ```
|
||||
/// 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 @@ fn with_filename<T: BytesContainer>(&self, filename: T) -> Self {
|
||||
/// 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.
|
||||
|
Loading…
Reference in New Issue
Block a user