danielhenrymantilla / rust-uninit

Read trait fixed to soundly work with uninitalized memory
MIT License
25 stars 2 forks source link

Add `Out::slice_from_raw_parts` #11

Closed kupiakos closed 10 months ago

kupiakos commented 10 months ago

For use with C interfaces:

#[no_mangle]
pub unsafe extern "C" foo(data: *mut u8, size: usize) {
    // Before (the turbofish is necessary):
    let buf = Out::from(slice::from_raw_parts_mut(data.cast::<MaybeUninit<u8>>(), size));
    // After:
    let buf = Out::slice_from_raw_parts(data, size);
}