@@ -1463,6 +1463,30 @@ impl PathBuf {
1463
1463
true
1464
1464
}
1465
1465
1466
+ /// Yields a mutable reference to the underlying [`OsString`] instance.
1467
+ ///
1468
+ /// # Examples
1469
+ ///
1470
+ /// ```
1471
+ /// #![feature(path_as_mut_os_str)]
1472
+ /// use std::path::{Path, PathBuf};
1473
+ ///
1474
+ /// let mut path = PathBuf::from("/foo");
1475
+ ///
1476
+ /// path.push("bar");
1477
+ /// assert_eq!(path, Path::new("/foo/bar"));
1478
+ ///
1479
+ /// // OsString's `push` does not add a separator.
1480
+ /// path.as_mut_os_string().push("baz");
1481
+ /// assert_eq!(path, Path::new("/foo/barbaz"));
1482
+ /// ```
1483
+ #[ unstable( feature = "path_as_mut_os_str" , issue = "105021" ) ]
1484
+ #[ must_use]
1485
+ #[ inline]
1486
+ pub fn as_mut_os_string ( & mut self ) -> & mut OsString {
1487
+ & mut self . inner
1488
+ }
1489
+
1466
1490
/// Consumes the `PathBuf`, yielding its internal [`OsString`] storage.
1467
1491
///
1468
1492
/// # Examples
@@ -1993,6 +2017,28 @@ impl Path {
1993
2017
& self . inner
1994
2018
}
1995
2019
2020
+ /// Yields a mutable reference to the underlying [`OsStr`] slice.
2021
+ ///
2022
+ /// # Examples
2023
+ ///
2024
+ /// ```
2025
+ /// #![feature(path_as_mut_os_str)]
2026
+ /// use std::path::{Path, PathBuf};
2027
+ ///
2028
+ /// let mut path = PathBuf::from("/Foo.TXT").into_boxed_path();
2029
+ ///
2030
+ /// assert_ne!(&*path, Path::new("/foo.txt"));
2031
+ ///
2032
+ /// path.as_mut_os_str().make_ascii_lowercase();
2033
+ /// assert_eq!(&*path, Path::new("/foo.txt"));
2034
+ /// ```
2035
+ #[ unstable( feature = "path_as_mut_os_str" , issue = "105021" ) ]
2036
+ #[ must_use]
2037
+ #[ inline]
2038
+ pub fn as_mut_os_str ( & mut self ) -> & mut OsStr {
2039
+ & mut self . inner
2040
+ }
2041
+
1996
2042
/// Yields a [`&str`] slice if the `Path` is valid unicode.
1997
2043
///
1998
2044
/// This conversion may entail doing a check for UTF-8 validity.
0 commit comments