1
Fork 0

add comments about safety

This commit is contained in:
TyPR124 2020-03-16 16:12:54 -04:00
parent ef2957de13
commit 21975a1aaa
3 changed files with 16 additions and 0 deletions

View file

@ -106,11 +106,17 @@ impl Buf {
#[inline]
pub fn as_slice(&self) -> &Slice {
// Safety: Slice just wraps [u8],
// and &*self.inner is &[u8], therefore
// transmuting &[u8] to &Slice is safe.
unsafe { mem::transmute(&*self.inner) }
}
#[inline]
pub fn as_mut_slice(&mut self) -> &mut Slice {
// Safety: Slice just wraps [u8],
// and &mut *self.inner is &mut [u8], therefore
// transmuting &mut [u8] to &mut Slice is safe.
unsafe { mem::transmute(&mut *self.inner) }
}