Function presser::readback_from_ffi

source ·
pub unsafe fn readback_from_ffi<'a, T, S, F>(
    slab: &'a mut S,
    fill_slab: F
) -> Result<&'a T, Error>where
    S: Slab + ?Sized,
    F: FnOnce(*mut c_void),
Expand description

Helper to read back data from an ffi function which expects a pointer into which it will write a T.

fill_slab is a function in which you must guarantee to write a valid T at the given *mut c_void pointer.

slab will be used as the backing data to write the T into. The *mut c_void pointer given to the function will be as close to the beginning of slab as possible while upholding the alignment requirements of T. If a T cannot fit into slab while upholding those alignment requirements and the size of T, an error will be returned and fill_slab will not be called.

Safety

You must during the execution of fill_slab fully-initialize a valid* T at the given pointer.

* Validity is a complex topic not to be taken lightly. See this rust reference page for more details.