diff options
author | Ivan Tham <pickfire@riseup.net> | 2020-08-07 14:16:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-07 14:16:52 +0800 |
commit | 3d1388f514ab18ad798251f511c54097ba5c60ca (patch) | |
tree | 13b7939b480fa7ba0b0492c5fbef64fc941c4d7b | |
parent | 63e34422bbaf4ae4ed5ae7309183185aa2aa13a4 (diff) | |
download | rust-3d1388f514ab18ad798251f511c54097ba5c60ca.tar.gz |
Add more examples to Path ends_with
We faced a footgun when using ends_with to check extension,
showing an example could prevent that.
-rw-r--r-- | library/std/src/path.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 392c815ef28..bc24c1e65c8 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -2112,6 +2112,11 @@ impl Path { /// let path = Path::new("/etc/passwd"); /// /// assert!(path.ends_with("passwd")); + /// assert!(path.ends_with("etc/passwd")); + /// assert!(path.ends_with("/etc/passwd")); + /// + /// assert!(!path.ends_with("/passwd")); + /// assert!(!path.ends_with("wd")); // use .extension() instead /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn ends_with<P: AsRef<Path>>(&self, child: P) -> bool { |