about summary refs log tree commit diff
path: root/src/libstd/path.rs
diff options
context:
space:
mode:
authorJeremy Soller <jackpot51@gmail.com>2016-11-19 20:31:42 -0700
committerJeremy Soller <jackpot51@gmail.com>2016-11-19 20:31:42 -0700
commitae2029fc62d744e252a5a077ce0dfbf2d1683d25 (patch)
tree8b7a0aebcf10870fd331c8d76dc00f19091b2713 /src/libstd/path.rs
parent2556400a5d4c9b56084332c29b6c91ac5cd3a9fa (diff)
parent0bd2ce62b27e2b9a7dfe92fc23d9098854008089 (diff)
downloadrust-ae2029fc62d744e252a5a077ce0dfbf2d1683d25.tar.gz
rust-ae2029fc62d744e252a5a077ce0dfbf2d1683d25.zip
Merge branch 'master' into redox
Diffstat (limited to 'src/libstd/path.rs')
-rw-r--r--src/libstd/path.rs40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs
index 3e414a28a30..8bf9bbb1320 100644
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -25,11 +25,18 @@
 //!
 //! ```rust
 //! use std::path::Path;
+//! use std::ffi::OsStr;
 //!
 //! let path = Path::new("/tmp/foo/bar.txt");
-//! let file = path.file_name();
+//!
+//! let parent = path.parent();
+//! assert_eq!(parent, Some(Path::new("/tmp/foo")));
+//!
+//! let file_stem = path.file_stem();
+//! assert_eq!(file_stem, Some(OsStr::new("bar")));
+//!
 //! let extension = path.extension();
-//! let parent_dir = path.parent();
+//! assert_eq!(extension, Some(OsStr::new("txt")));
 //! ```
 //!
 //! To build or modify paths, use `PathBuf`:
@@ -990,17 +997,24 @@ impl PathBuf {
     ///
     /// # Examples
     ///
+    /// Pushing a relative path extends the existing path:
+    ///
     /// ```
     /// use std::path::PathBuf;
     ///
-    /// let mut path = PathBuf::new();
-    /// path.push("/tmp");
+    /// let mut path = PathBuf::from("/tmp");
     /// path.push("file.bk");
     /// assert_eq!(path, PathBuf::from("/tmp/file.bk"));
+    /// ```
+    ///
+    /// Pushing an absolute path replaces the existing path:
     ///
-    /// // Pushing an absolute path replaces the current path
-    /// path.push("/etc/passwd");
-    /// assert_eq!(path, PathBuf::from("/etc/passwd"));
+    /// ```
+    /// use std::path::PathBuf;
+    ///
+    /// let mut path = PathBuf::from("/tmp");
+    /// path.push("/etc");
+    /// assert_eq!(path, PathBuf::from("/etc"));
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn push<P: AsRef<Path>>(&mut self, path: P) {
@@ -1319,13 +1333,19 @@ impl AsRef<OsStr> for PathBuf {
 ///
 /// ```
 /// use std::path::Path;
+/// use std::ffi::OsStr;
 ///
 /// let path = Path::new("/tmp/foo/bar.txt");
-/// let file = path.file_name();
+///
+/// let parent = path.parent();
+/// assert_eq!(parent, Some(Path::new("/tmp/foo")));
+///
+/// let file_stem = path.file_stem();
+/// assert_eq!(file_stem, Some(OsStr::new("bar")));
+///
 /// let extension = path.extension();
-/// let parent_dir = path.parent();
+/// assert_eq!(extension, Some(OsStr::new("txt")));
 /// ```
-///
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct Path {
     inner: OsStr,