mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-03 18:43:38 +00:00
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:
commit
3f3250500f
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user