1
Fork 0

libstd: add example for PathBuf::push

This commit is contained in:
Kevin Butler 2015-11-09 03:42:22 +00:00
parent 5b4986fa57
commit 621e259b78

View file

@ -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())