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. https://github.com/rust-dc/fish-manpage-completions/pull/106/commits/2c155e50b2d9e607174908b3f80f1dcf92693eee
This commit is contained in:
commit
3f3250500f
1 changed files with 7 additions and 2 deletions
|
@ -2057,9 +2057,14 @@ impl Path {
|
||||||
/// ```
|
/// ```
|
||||||
/// use std::path::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")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn ends_with<P: AsRef<Path>>(&self, child: P) -> bool {
|
pub fn ends_with<P: AsRef<Path>>(&self, child: P) -> bool {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue