about summary refs log tree commit diff
path: root/src/libstd/ffi
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd/ffi')
-rw-r--r--src/libstd/ffi/os_str.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs
index 77da97219b1..2f921ce7a5f 100644
--- a/src/libstd/ffi/os_str.rs
+++ b/src/libstd/ffi/os_str.rs
@@ -379,6 +379,14 @@ impl ops::Index<ops::RangeFull> for OsString {
     }
 }
 
+#[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 @@ impl ops::Deref for OsString {
     }
 }
 
+#[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 @@ impl 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.