mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-08 09:38:26 +03:00
allowing getting &mut OsStr from OsString
This commit is contained in:
@@ -379,6 +379,14 @@ fn index(&self, _index: ops::RangeFull) -> &OsStr {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "mut_osstr", since = "1.44.0")]
|
||||
impl ops::IndexMut<ops::RangeFull> for OsString {
|
||||
#[inline]
|
||||
fn index_mut(&mut self, _index: ops::RangeFull) -> &mut OsStr {
|
||||
OsStr::from_inner_mut(self.inner.as_mut_slice())
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl ops::Deref for OsString {
|
||||
type Target = OsStr;
|
||||
@@ -389,6 +397,14 @@ fn deref(&self) -> &OsStr {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "mut_osstr", since = "1.44.0")]
|
||||
impl ops::DerefMut for OsString {
|
||||
#[inline]
|
||||
fn deref_mut(&mut self) -> &mut OsStr {
|
||||
&mut self[..]
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "osstring_default", since = "1.9.0")]
|
||||
impl Default for OsString {
|
||||
/// Constructs an empty `OsString`.
|
||||
@@ -512,6 +528,11 @@ fn from_inner(inner: &Slice) -> &OsStr {
|
||||
unsafe { &*(inner as *const Slice as *const OsStr) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_inner_mut(inner: &mut Slice) -> &mut OsStr {
|
||||
unsafe { &mut *(inner as *mut Slice as *mut OsStr) }
|
||||
}
|
||||
|
||||
/// Yields a [`&str`] slice if the `OsStr` is valid Unicode.
|
||||
///
|
||||
/// This conversion may entail doing a check for UTF-8 validity.
|
||||
|
||||
@@ -80,6 +80,11 @@ pub fn as_slice(&self) -> &Slice {
|
||||
unsafe { mem::transmute(self.inner.as_slice()) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_mut_slice(&mut self) -> &mut Slice {
|
||||
unsafe { mem::transmute(self.inner.as_mut_slice()) }
|
||||
}
|
||||
|
||||
pub fn into_string(self) -> Result<String, Buf> {
|
||||
self.inner.into_string().map_err(|buf| Buf { inner: buf })
|
||||
}
|
||||
|
||||
@@ -109,6 +109,11 @@ pub fn as_slice(&self) -> &Slice {
|
||||
unsafe { mem::transmute(&*self.inner) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_mut_slice(&mut self) -> &mut Slice {
|
||||
unsafe { mem::transmute(&mut *self.inner) }
|
||||
}
|
||||
|
||||
pub fn into_string(self) -> Result<String, Buf> {
|
||||
String::from_utf8(self.inner).map_err(|p| Buf { inner: p.into_bytes() })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user