Skip to content

Instantly share code, notes, and snippets.

@Aatch
Created June 25, 2013 07:54
Show Gist options
  • Save Aatch/5856745 to your computer and use it in GitHub Desktop.
Save Aatch/5856745 to your computer and use it in GitHub Desktop.
My Magnificent Hack
enum opaque {}
trait thing {
pub fn foo(&self);
}
impl thing for opaque {
pub fn foo(&self) {
unsafe {
let o : *[int,..8] = std::cast::transmute(self);
println(fmt!("%?", *o));
}
}
}
fn main() {
unsafe {
let o = test();
o.foo();
}
}
unsafe fn test() -> &'static thing {
let src = [987654321,..8];
let a = std::libc::malloc(128 as std::libc::size_t) as *mut [int,..8];
let srcp = &src;
std::ptr::copy_memory(a, srcp, 1);
println(fmt!("%?", a));
let o : &'static opaque = std::cast::transmute(a);
o as &thing
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment