]> git.lizzy.rs Git - rust.git/commitdiff
Add some edge cases to the documentation of `Path`
authorTobias Bucher <tobiasbucher5991@gmail.com>
Thu, 18 Jan 2018 00:22:20 +0000 (01:22 +0100)
committerTobias Bucher <tobiasbucher5991@gmail.com>
Thu, 18 Jan 2018 00:22:20 +0000 (01:22 +0100)
Affected methods are `starts_with` and `strip_prefix`.

src/libstd/path.rs

index 7631a9a44bbe72f1b1c2b911a0638fbe554755ab..ed102c2949ede7a667afc435e9f7d1c0a4ea88a1 100644 (file)
@@ -1869,7 +1869,11 @@ pub fn file_name(&self) -> Option<&OsStr> {
     ///
     /// let path = Path::new("/test/haha/foo.txt");
     ///
+    /// assert_eq!(path.strip_prefix("/"), Ok(Path::new("test/haha/foo.txt")));
     /// assert_eq!(path.strip_prefix("/test"), Ok(Path::new("haha/foo.txt")));
+    /// assert_eq!(path.strip_prefix("/test/"), Ok(Path::new("haha/foo.txt")));
+    /// assert_eq!(path.strip_prefix("/test/haha/foo.txt"), Ok(Path::new("")));
+    /// assert_eq!(path.strip_prefix("/test/haha/foo.txt/"), Ok(Path::new("")));
     /// assert_eq!(path.strip_prefix("test").is_ok(), false);
     /// assert_eq!(path.strip_prefix("/haha").is_ok(), false);
     /// ```
@@ -1900,6 +1904,9 @@ fn _strip_prefix<'a>(&'a self, base: &'a Path)
     /// let path = Path::new("/etc/passwd");
     ///
     /// assert!(path.starts_with("/etc"));
+    /// assert!(path.starts_with("/etc/"));
+    /// assert!(path.starts_with("/etc/passwd"));
+    /// assert!(path.starts_with("/etc/passwd/"));
     ///
     /// assert!(!path.starts_with("/e"));
     /// ```