reduce clutter... too many imports

This commit is contained in:
Tshepang Mbambo
2025-05-24 22:17:55 +02:00
parent a3bd12b88a
commit 248f4b2ad2

View File

@@ -2739,30 +2739,30 @@ impl Path {
/// # Examples
///
/// ```
/// use std::path::{Path, PathBuf};
/// use std::path::Path;
///
/// let path = Path::new("foo.rs");
/// assert_eq!(path.with_extension("txt"), PathBuf::from("foo.txt"));
/// assert_eq!(path.with_extension(""), PathBuf::from("foo"));
/// assert_eq!(path.with_extension("txt"), Path::new("foo.txt"));
/// assert_eq!(path.with_extension(""), Path::new("foo"));
/// ```
///
/// Handling multiple extensions:
///
/// ```
/// use std::path::{Path, PathBuf};
/// use std::path::Path;
///
/// let path = Path::new("foo.tar.gz");
/// assert_eq!(path.with_extension("xz"), PathBuf::from("foo.tar.xz"));
/// assert_eq!(path.with_extension("").with_extension("txt"), PathBuf::from("foo.txt"));
/// assert_eq!(path.with_extension("xz"), Path::new("foo.tar.xz"));
/// assert_eq!(path.with_extension("").with_extension("txt"), Path::new("foo.txt"));
/// ```
///
/// Adding an extension where one did not exist:
///
/// ```
/// use std::path::{Path, PathBuf};
/// use std::path::Path;
///
/// let path = Path::new("foo");
/// assert_eq!(path.with_extension("rs"), PathBuf::from("foo.rs"));
/// assert_eq!(path.with_extension("rs"), Path::new("foo.rs"));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf {