Fix std::path::Path::file_name() doc

This commit is contained in:
ggomez
2016-07-05 11:36:43 +02:00
committed by Guillaume Gomez
parent 0f4c4f8c29
commit 0d78f6b40f

View File

@@ -1529,8 +1529,7 @@ impl Path {
/// The final component of the path, if it is a normal file. /// The final component of the path, if it is a normal file.
/// ///
/// If the path terminates in `.`, `..`, or consists solely of a root of /// If the path terminates in `..`, `file_name` will return `None`.
/// prefix, `file_name` will return `None`.
/// ///
/// # Examples /// # Examples
/// ///
@@ -1543,6 +1542,17 @@ impl Path {
/// ///
/// assert_eq!(Some(os_str), path.file_name()); /// assert_eq!(Some(os_str), path.file_name());
/// ``` /// ```
///
/// # Other examples
///
/// ```
/// use std::path::Path;
/// use std::ffi::OsStr;
///
/// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("foo.txt/.").file_name());
/// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("foo.txt/.//").file_name());
/// assert_eq!(None, Path::new("foo.txt/..").file_name());
/// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn file_name(&self) -> Option<&OsStr> { pub fn file_name(&self) -> Option<&OsStr> {
self.components().next_back().and_then(|p| { self.components().next_back().and_then(|p| {