Skip to content
Snippets Groups Projects
Commit c5452b8c authored by Florian Hartwig's avatar Florian Hartwig
Browse files

Don't transmute & to &mut

parent a91ee81b
No related branches found
No related tags found
No related merge requests found
...@@ -64,7 +64,10 @@ impl MemRef { ...@@ -64,7 +64,10 @@ impl MemRef {
#[inline] #[inline]
pub fn bytes_mut(&mut self) -> &mut [u8] { pub fn bytes_mut(&mut self) -> &mut [u8] {
unsafe { mem::transmute(self.bytes()) } use std::slice;
unsafe {
slice::from_raw_parts_mut(self.ptr(), self.mem().len)
}
} }
#[inline] #[inline]
......
...@@ -97,24 +97,28 @@ impl Bytes { ...@@ -97,24 +97,28 @@ impl Bytes {
fn obj(&self) -> &ByteStrPriv { fn obj(&self) -> &ByteStrPriv {
unsafe { unsafe {
let obj = if self.is_inline() { mem::transmute(self.to_trait_object())
TraitObject {
data: mem::transmute(&self.data),
vtable: mem::transmute(self.vtable - 1),
}
} else {
TraitObject {
data: self.data,
vtable: mem::transmute(self.vtable),
}
};
mem::transmute(obj)
} }
} }
fn obj_mut(&mut self) -> &mut ByteStrPriv { fn obj_mut(&mut self) -> &mut ByteStrPriv {
unsafe { mem::transmute(self.obj()) } unsafe {
mem::transmute(self.to_trait_object())
}
}
unsafe fn to_trait_object(&self) -> TraitObject {
if self.is_inline() {
TraitObject {
data: mem::transmute(&self.data),
vtable: mem::transmute(self.vtable - 1),
}
} else {
TraitObject {
data: self.data,
vtable: mem::transmute(self.vtable),
}
}
} }
fn is_inline(&self) -> bool { fn is_inline(&self) -> bool {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment