Skip to content

Commit

Permalink
Update for unsafe-any changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
reem committed Jan 3, 2015
1 parent 76126fc commit 541e21d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,20 @@ impl<'a> Writer for &'a mut NetworkStream {
fn flush(&mut self) -> IoResult<()> { (**self).flush() }
}

impl UncheckedBoxAnyDowncast for Box<NetworkStream + Send> {
unsafe fn downcast_unchecked<T: 'static>(self) -> Box<T> {
let to = *mem::transmute::<&Box<NetworkStream + Send>, &raw::TraitObject>(&self);
// Prevent double-free.
mem::forget(self);
mem::transmute(to.data)
impl UnsafeAnyExt for NetworkStream + Send {
unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T {
mem::transmute(mem::transmute::<&NetworkStream + Send,
raw::TraitObject>(self).data)
}

unsafe fn downcast_mut_unchecked<T: 'static>(&mut self) -> &mut T {
mem::transmute(mem::transmute::<&mut NetworkStream + Send,
raw::TraitObject>(self).data)
}

unsafe fn downcast_unchecked<T: 'static>(self: Box<NetworkStream + Send>) -> Box<T> {
mem::transmute(mem::transmute::<Box<NetworkStream + Send>,
raw::TraitObject>(self).data)
}
}

Expand Down

0 comments on commit 541e21d

Please sign in to comment.