Auto merge of #75246 - pickfire:patch-5, r=Amanieu

Add more examples to Path ends_with

We faced a footgun when using ends_with to check extension,
showing an example could prevent that.

2c155e50b2
This commit is contained in:
bors 2020-08-15 19:51:44 +00:00
commit 3f3250500f

View File

@ -2057,9 +2057,14 @@ impl Path {
/// ```
/// use std::path::Path;
///
/// let path = Path::new("/etc/passwd");
/// let path = Path::new("/etc/resolv.conf");
///
/// assert!(path.ends_with("passwd"));
/// assert!(path.ends_with("resolv.conf"));
/// assert!(path.ends_with("etc/resolv.conf"));
/// assert!(path.ends_with("/etc/resolv.conf"));
///
/// assert!(!path.ends_with("/resolv.conf"));
/// assert!(!path.ends_with("conf")); // use .extension() instead
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn ends_with<P: AsRef<Path>>(&self, child: P) -> bool {