Function presser::readback_slice_from_ffi
source · pub unsafe fn readback_slice_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, usize) -> usize,
Expand description
Helper to read back data from an ffi function which expects a pointer into which it will write
a slice (in C language, an array) of T
s.
fill_slab
is a function which takes as parameters first an aligned (for T)
*mut c_void
and second the number of bytes left in slab
available for writing.
It must then write a slice of T
s into the given pointer and return the length, in units of
T
, of the slice it wrote.
slab
will be used as the backing data to write the slice of T
s 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
.
Safety
You must during the execution of fill_slab
fully-initialize a valid* slice of T
beginning at the given pointer and with length greater than or equal to the length you return
from that function.
* Validity is a complex topic not to be taken lightly. See this rust reference page for more details.