Created
October 10, 2012 13:57
-
-
Save ben0x539/3865798 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
fn read_struct<R: io::Reader, T>(reader: R, obj: &mut T) { | |
let size: uint = sys::size_of::<T>(); | |
unsafe { | |
let borrowed_ptr: &u8 = cast::reinterpret_cast(&obj); | |
let ptr: *u8 = ptr::to_unsafe_ptr(borrowed_ptr); | |
do vec::raw::buf_as_slice(ptr, size) |buf: &[u8]| { | |
let mut_buf: &[mut u8] = cast::reinterpret_cast(&buf); | |
let ret = reader.read(mut_buf, size); | |
assert ret == size; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment