Rollup merge of #34659 - GuillaumeGomez:path_file_name, r=steveklabnik

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

Fixes #34632

r? @steveklabnik
This commit is contained in:
Manish Goregaokar 2016-07-08 13:14:20 +05:30
commit f4ae98ab8c
1 changed files with 12 additions and 2 deletions

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| {