@@ -1189,8 +1189,13 @@ impl PathBuf {
1189
1189
/// If [`self.file_name`] was [`None`], this is equivalent to pushing
1190
1190
/// `file_name`.
1191
1191
///
1192
+ /// Otherwise it is equivalent to calling [`pop`] and then pushing
1193
+ /// `file_name`. The new path will be a sibling of the original path.
1194
+ /// (That is, it will have the same parent.)
1195
+ ///
1192
1196
/// [`self.file_name`]: struct.PathBuf.html#method.file_name
1193
1197
/// [`None`]: ../../std/option/enum.Option.html#variant.None
1198
+ /// [`pop`]: struct.PathBuf.html#method.pop
1194
1199
///
1195
1200
/// # Examples
1196
1201
///
@@ -1725,7 +1730,10 @@ impl Path {
1725
1730
} )
1726
1731
}
1727
1732
1728
- /// Returns the final component of the `Path`, if it is a normal file.
1733
+ /// Returns the final component of the `Path`, if there is one.
1734
+ ///
1735
+ /// If the path is a normal file, this is the file name. If it's the path of a directory, this
1736
+ /// is the directory name.
1729
1737
///
1730
1738
/// Returns [`None`] If the path terminates in `..`.
1731
1739
///
@@ -1737,10 +1745,12 @@ impl Path {
1737
1745
/// use std::path::Path;
1738
1746
/// use std::ffi::OsStr;
1739
1747
///
1740
- /// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("foo.txt").file_name());
1748
+ /// assert_eq!(Some(OsStr::new("bin")), Path::new("/usr/bin/").file_name());
1749
+ /// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("tmp/foo.txt").file_name());
1741
1750
/// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("foo.txt/.").file_name());
1742
1751
/// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("foo.txt/.//").file_name());
1743
1752
/// assert_eq!(None, Path::new("foo.txt/..").file_name());
1753
+ /// assert_eq!(None, Path::new("/").file_name());
1744
1754
/// ```
1745
1755
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1746
1756
pub fn file_name ( & self ) -> Option < & OsStr > {
@@ -1926,6 +1936,9 @@ impl Path {
1926
1936
///
1927
1937
/// let path = Path::new("/tmp/foo.txt");
1928
1938
/// assert_eq!(path.with_file_name("bar.txt"), PathBuf::from("/tmp/bar.txt"));
1939
+ ///
1940
+ /// let path = Path::new("/tmp");
1941
+ /// assert_eq!(path.with_file_name("var"), PathBuf::from("/var"));
1929
1942
/// ```
1930
1943
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1931
1944
pub fn with_file_name < S : AsRef < OsStr > > ( & self , file_name : S ) -> PathBuf {
0 commit comments