Add more examples to Path ends_with
We faced a footgun when using ends_with to check extension, showing an example could prevent that.
This commit is contained in:
parent
63e34422bb
commit
3d1388f514
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user