File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -379,6 +379,14 @@ impl ops::Index<ops::RangeFull> for OsString {
379
379
}
380
380
}
381
381
382
+ #[ stable( feature = "mut_osstr" , since = "1.44.0" ) ]
383
+ impl ops:: IndexMut < ops:: RangeFull > for OsString {
384
+ #[ inline]
385
+ fn index_mut ( & mut self , _index : ops:: RangeFull ) -> & mut OsStr {
386
+ OsStr :: from_inner_mut ( self . inner . as_mut_slice ( ) )
387
+ }
388
+ }
389
+
382
390
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
383
391
impl ops:: Deref for OsString {
384
392
type Target = OsStr ;
@@ -389,6 +397,14 @@ impl ops::Deref for OsString {
389
397
}
390
398
}
391
399
400
+ #[ stable( feature = "mut_osstr" , since = "1.44.0" ) ]
401
+ impl ops:: DerefMut for OsString {
402
+ #[ inline]
403
+ fn deref_mut ( & mut self ) -> & mut OsStr {
404
+ & mut self [ ..]
405
+ }
406
+ }
407
+
392
408
#[ stable( feature = "osstring_default" , since = "1.9.0" ) ]
393
409
impl Default for OsString {
394
410
/// Constructs an empty `OsString`.
@@ -512,6 +528,11 @@ impl OsStr {
512
528
unsafe { & * ( inner as * const Slice as * const OsStr ) }
513
529
}
514
530
531
+ #[ inline]
532
+ fn from_inner_mut ( inner : & mut Slice ) -> & mut OsStr {
533
+ unsafe { & mut * ( inner as * mut Slice as * mut OsStr ) }
534
+ }
535
+
515
536
/// Yields a [`&str`] slice if the `OsStr` is valid Unicode.
516
537
///
517
538
/// This conversion may entail doing a check for UTF-8 validity.
Original file line number Diff line number Diff line change @@ -80,6 +80,11 @@ impl Buf {
80
80
unsafe { mem:: transmute ( self . inner . as_slice ( ) ) }
81
81
}
82
82
83
+ #[ inline]
84
+ pub fn as_mut_slice ( & mut self ) -> & mut Slice {
85
+ unsafe { mem:: transmute ( self . inner . as_mut_slice ( ) ) }
86
+ }
87
+
83
88
pub fn into_string ( self ) -> Result < String , Buf > {
84
89
self . inner . into_string ( ) . map_err ( |buf| Buf { inner : buf } )
85
90
}
Original file line number Diff line number Diff line change @@ -109,6 +109,11 @@ impl Buf {
109
109
unsafe { mem:: transmute ( & * self . inner ) }
110
110
}
111
111
112
+ #[ inline]
113
+ pub fn as_mut_slice ( & mut self ) -> & mut Slice {
114
+ unsafe { mem:: transmute ( & mut * self . inner ) }
115
+ }
116
+
112
117
pub fn into_string ( self ) -> Result < String , Buf > {
113
118
String :: from_utf8 ( self . inner ) . map_err ( |p| Buf { inner : p. into_bytes ( ) } )
114
119
}
You can’t perform that action at this time.
0 commit comments