Skip to content

Instantly share code, notes, and snippets.

@cdlm
Last active June 29, 2016 18:39
Show Gist options
  • Save cdlm/67e62daee9c4b60e5d062b59d819677a to your computer and use it in GitHub Desktop.
Save cdlm/67e62daee9c4b60e5d062b59d819677a to your computer and use it in GitHub Desktop.
Evil things in Rust :]
#[derive(Debug)]
struct Foo { bar: *mut Bar }
#[derive(Debug)]
struct Bar { foo: *mut Foo }
#[cfg(test)]
mod tests {
use super::{Foo,Bar};
use std::ptr;
#[test]
fn it_works() {
let mut bar = Bar { foo: ptr::null_mut() };
let mut foo = Foo { bar: &mut bar as *mut Bar };
bar.foo = &mut foo as *mut Foo;
assert_eq!(foo.bar, unsafe { (*bar.foo).bar });
assert_eq!(bar.foo, unsafe { (*foo.bar).foo });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment