add comment about maintaining OsStr encoding
This commit is contained in:
parent
e4a65e83e7
commit
45416cd91a
@ -534,6 +534,8 @@ fn from_inner(inner: &Slice) -> &OsStr {
|
||||
fn from_inner_mut(inner: &mut Slice) -> &mut OsStr {
|
||||
// Safety: OsStr is just a wrapper of Slice,
|
||||
// therefore converting &mut Slice to &mut OsStr is safe.
|
||||
// Any method that mutates OsStr must be careful not to
|
||||
// break platform-specific encoding, in particular Wtf8 on Windows.
|
||||
unsafe { &mut *(inner as *mut Slice as *mut OsStr) }
|
||||
}
|
||||
|
||||
|
@ -87,6 +87,8 @@ pub fn as_mut_slice(&mut self) -> &mut Slice {
|
||||
// Safety: Slice is just a wrapper for Wtf8,
|
||||
// and self.inner.as_mut_slice() returns &mut Wtf8.
|
||||
// Therefore, transmuting &mut Wtf8 to &mut Slice is safe.
|
||||
// Additionally, care should be taken to ensure the slice
|
||||
// is always valid Wtf8.
|
||||
unsafe { mem::transmute(self.inner.as_mut_slice()) }
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user