Skip to content

Commit 4eb4e10

Browse files
committed
edit docs of PathBuf::set_file_name
to show this method might replace or remove the extension, not just the file stem also edit docs of `Path::with_file_name` because it calls `PathBuf::set_file_name`
1 parent df7fd99 commit 4eb4e10

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

library/std/src/path.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1395,11 +1395,16 @@ impl PathBuf {
13951395
///
13961396
/// let mut buf = PathBuf::from("/");
13971397
/// assert!(buf.file_name() == None);
1398-
/// buf.set_file_name("bar");
1399-
/// assert!(buf == PathBuf::from("/bar"));
1398+
///
1399+
/// buf.set_file_name("foo.txt");
1400+
/// assert!(buf == PathBuf::from("/foo.txt"));
14001401
/// assert!(buf.file_name().is_some());
1401-
/// buf.set_file_name("baz.txt");
1402-
/// assert!(buf == PathBuf::from("/baz.txt"));
1402+
///
1403+
/// buf.set_file_name("bar.txt");
1404+
/// assert!(buf == PathBuf::from("/bar.txt"));
1405+
///
1406+
/// buf.set_file_name("baz");
1407+
/// assert!(buf == PathBuf::from("/baz"));
14031408
/// ```
14041409
#[stable(feature = "rust1", since = "1.0.0")]
14051410
pub fn set_file_name<S: AsRef<OsStr>>(&mut self, file_name: S) {
@@ -2562,7 +2567,8 @@ impl Path {
25622567
/// ```
25632568
/// use std::path::{Path, PathBuf};
25642569
///
2565-
/// let path = Path::new("/tmp/foo.txt");
2570+
/// let path = Path::new("/tmp/foo.png");
2571+
/// assert_eq!(path.with_file_name("bar"), PathBuf::from("/tmp/bar"));
25662572
/// assert_eq!(path.with_file_name("bar.txt"), PathBuf::from("/tmp/bar.txt"));
25672573
///
25682574
/// let path = Path::new("/tmp");

0 commit comments

Comments
 (0)