Skip to content

Commit f53d062

Browse files
committed
Minor rewriting of std::path::Path::push doc example.
1 parent b6b98ea commit f53d062

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)