Last active
June 29, 2016 18:39
-
-
Save cdlm/67e62daee9c4b60e5d062b59d819677a to your computer and use it in GitHub Desktop.
Evil things in Rust :]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[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