diff options
| author | Kevin Butler <haqkrs@gmail.com> | 2015-11-09 03:42:22 +0000 |
|---|---|---|
| committer | Kevin Butler <haqkrs@gmail.com> | 2015-11-09 03:42:22 +0000 |
| commit | 621e259b78fb992745c3cf194e28be5a8610a97c (patch) | |
| tree | 25fb706026fe5c2883548f9cbfd74038defe2ea3 | |
| parent | 5b4986fa5753b9662c8baab1c31b9b79bc84ca19 (diff) | |
| download | rust-621e259b78fb992745c3cf194e28be5a8610a97c.tar.gz rust-621e259b78fb992745c3cf194e28be5a8610a97c.zip | |
libstd: add example for PathBuf::push
| -rw-r--r-- | src/libstd/path.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs index b9a58a11764..6b5e16ae113 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1013,6 +1013,21 @@ impl PathBuf { /// * if `path` has a root but no prefix (e.g. `\windows`), it /// replaces everything except for the prefix (if any) of `self`. /// * if `path` has a prefix but no root, it replaces `self`. + /// + /// # Examples + /// + /// ``` + /// use std::path::PathBuf; + /// + /// let mut path = PathBuf::new(); + /// path.push("/tmp"); + /// path.push("file.bk"); + /// assert_eq!(path, PathBuf::from("/tmp/file.bk")); + /// + /// // Pushing an absolute path replaces the current path + /// path.push("/etc/passwd"); + /// assert_eq!(path, PathBuf::from("/etc/passwd")); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn push<P: AsRef<Path>>(&mut self, path: P) { self._push(path.as_ref()) |
