Skip to content

Commit 621e259

Browse files
committed
libstd: add example for PathBuf::push
1 parent 5b4986f commit 621e259

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/libstd/path.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,21 @@ impl PathBuf {
10131013
/// * if `path` has a root but no prefix (e.g. `\windows`), it
10141014
/// replaces everything except for the prefix (if any) of `self`.
10151015
/// * if `path` has a prefix but no root, it replaces `self`.
1016+
///
1017+
/// # Examples
1018+
///
1019+
/// ```
1020+
/// use std::path::PathBuf;
1021+
///
1022+
/// let mut path = PathBuf::new();
1023+
/// path.push("/tmp");
1024+
/// path.push("file.bk");
1025+
/// assert_eq!(path, PathBuf::from("/tmp/file.bk"));
1026+
///
1027+
/// // Pushing an absolute path replaces the current path
1028+
/// path.push("/etc/passwd");
1029+
/// assert_eq!(path, PathBuf::from("/etc/passwd"));
1030+
/// ```
10161031
#[stable(feature = "rust1", since = "1.0.0")]
10171032
pub fn push<P: AsRef<Path>>(&mut self, path: P) {
10181033
self._push(path.as_ref())

0 commit comments

Comments
 (0)