Implement DerefMut for PathBuf
This commit is contained in:
parent
8a09420ac4
commit
2c541786cf
@ -1724,6 +1724,14 @@ impl ops::Deref for PathBuf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "path_buf_deref_mut", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
impl ops::DerefMut for PathBuf {
|
||||||
|
#[inline]
|
||||||
|
fn deref_mut(&mut self) -> &mut Path {
|
||||||
|
Path::from_inner_mut(&mut self.inner)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl Borrow<Path> for PathBuf {
|
impl Borrow<Path> for PathBuf {
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -1976,6 +1984,12 @@ impl Path {
|
|||||||
unsafe { &*(s.as_ref() as *const OsStr as *const Path) }
|
unsafe { &*(s.as_ref() as *const OsStr as *const Path) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn from_inner_mut(inner: &mut OsStr) -> &mut Path {
|
||||||
|
// SAFETY: Path is just a wrapper around OsStr,
|
||||||
|
// therefore converting &mut OsStr to &mut Path is safe.
|
||||||
|
unsafe { &mut *(inner as *mut OsStr as *mut Path) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Yields the underlying [`OsStr`] slice.
|
/// Yields the underlying [`OsStr`] slice.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
|
Loading…
x
Reference in New Issue
Block a user