Created
January 5, 2014 21:18
-
-
Save uzytkownik/8274049 to your computer and use it in GitHub Desktop.
Casting unsafe pointer to struct containing borrowed pointer
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
struct Test<'t> { | |
i: &'t int | |
} | |
unsafe fn cast<'t>(test: &'t *mut std::libc::c_void) -> &'t mut Test<'t> { | |
&*(test.clone() as *mut Test<'t>) | |
} | |
pub fn main() { | |
unsafe { | |
let i = 1; | |
let mut t = Test{i: &i}; | |
let ptr = std::ptr::to_mut_unsafe_ptr(&t) as *mut std::libc::c_void; | |
let c = cast(&ptr); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment