提交 3f325050 编写于 作者: B bors

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
......@@ -2057,9 +2057,14 @@ fn _starts_with(&self, base: &Path) -> bool {
/// ```
/// use std::path::Path;
///
/// let path = Path::new("/etc/passwd");
/// let path = Path::new("/etc/resolv.conf");
///
/// assert!(path.ends_with("resolv.conf"));
/// assert!(path.ends_with("etc/resolv.conf"));
/// assert!(path.ends_with("/etc/resolv.conf"));
///
/// assert!(path.ends_with("passwd"));
/// 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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册