Skip to content

Commit 1b9c656

Browse files
committed
Add some edge cases to the documentation of Path
Affected methods are `starts_with` and `strip_prefix`.
1 parent 3e49ada commit 1b9c656

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/libstd/path.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1869,7 +1869,11 @@ impl Path {
18691869
///
18701870
/// let path = Path::new("/test/haha/foo.txt");
18711871
///
1872+
/// assert_eq!(path.strip_prefix("/"), Ok(Path::new("test/haha/foo.txt")));
18721873
/// assert_eq!(path.strip_prefix("/test"), Ok(Path::new("haha/foo.txt")));
1874+
/// assert_eq!(path.strip_prefix("/test/"), Ok(Path::new("haha/foo.txt")));
1875+
/// assert_eq!(path.strip_prefix("/test/haha/foo.txt"), Ok(Path::new("")));
1876+
/// assert_eq!(path.strip_prefix("/test/haha/foo.txt/"), Ok(Path::new("")));
18731877
/// assert_eq!(path.strip_prefix("test").is_ok(), false);
18741878
/// assert_eq!(path.strip_prefix("/haha").is_ok(), false);
18751879
/// ```
@@ -1900,6 +1904,9 @@ impl Path {
19001904
/// let path = Path::new("/etc/passwd");
19011905
///
19021906
/// assert!(path.starts_with("/etc"));
1907+
/// assert!(path.starts_with("/etc/"));
1908+
/// assert!(path.starts_with("/etc/passwd"));
1909+
/// assert!(path.starts_with("/etc/passwd/"));
19031910
///
19041911
/// assert!(!path.starts_with("/e"));
19051912
/// ```

0 commit comments

Comments
 (0)