about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2018-01-20 22:32:45 +0100
committerGitHub <noreply@github.com>2018-01-20 22:32:45 +0100
commitb21499e76875ff224b2555c042815efca08237b3 (patch)
tree041aec8f223d1cd42262edcef28f50395d1610c5 /src/libstd
parent5381dfb7d952af61ea04737e0aff171a884cc17c (diff)
parent1b9c65694354b6507627d4f1662a9123de9b764a (diff)
downloadrust-b21499e76875ff224b2555c042815efca08237b3.tar.gz
rust-b21499e76875ff224b2555c042815efca08237b3.zip
Rollup merge of #47532 - tbu-:pr_path_oddities, r=TimNN
Add some edge cases to the documentation of `Path`

Affected methods are `starts_with` and `strip_prefix`.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/path.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs
index 7631a9a44bb..ed102c2949e 100644
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -1869,7 +1869,11 @@ impl Path {
     ///
     /// 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 @@ impl 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"));
     /// ```