Skip to content

Commit 7bef60a

Browse files
authored
Auto merge of rust-lang#37754 - frewsxcv:path-push, r=GuillaumeGomez
Minor rewriting of `std::path::Path::push` doc example. None
2 parents 435246b + f53d062 commit 7bef60a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/libstd/path.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -983,17 +983,24 @@ impl PathBuf {
983983
///
984984
/// # Examples
985985
///
986+
/// Pushing a relative path extends the existing path:
987+
///
986988
/// ```
987989
/// use std::path::PathBuf;
988990
///
989-
/// let mut path = PathBuf::new();
990-
/// path.push("/tmp");
991+
/// let mut path = PathBuf::from("/tmp");
991992
/// path.push("file.bk");
992993
/// assert_eq!(path, PathBuf::from("/tmp/file.bk"));
994+
/// ```
995+
///
996+
/// Pushing an absolute path replaces the existing path:
997+
///
998+
/// ```
999+
/// use std::path::PathBuf;
9931000
///
994-
/// // Pushing an absolute path replaces the current path
995-
/// path.push("/etc/passwd");
996-
/// assert_eq!(path, PathBuf::from("/etc/passwd"));
1001+
/// let mut path = PathBuf::from("/tmp");
1002+
/// path.push("/etc");
1003+
/// assert_eq!(path, PathBuf::from("/etc"));
9971004
/// ```
9981005
#[stable(feature = "rust1", since = "1.0.0")]
9991006
pub fn push<P: AsRef<Path>>(&mut self, path: P) {

0 commit comments

Comments
 (0)