I have written bindings to CSV ZSV library which allows to read CSV files
without utf-8 checking using SIMD.
The C struct allows to assign a processing function, a FILE and fread like function.
for testing I'd like to just use some memory b"..." and custom read implementation.
But I horribly fail at unsafely passing pointer to &[u8] as STREAM to my
reading function.
Or is it best to use temporary file and be done ?
The fear I have is that I hit the problem again and again and again ?
It's about this myread function which should behave like read but just copy
some memory to zsv to make it happy.
Not sure wheret he Box::into_raw etc is best or whether I can just unsafe {
&csv_contents[..] } or such ?
The basic question is does Rust allow to turn any pointer into untyped pointer
and back into a different pointer even if its unsafe and 'know what you're
doing' thing ?
A boxed slice is a fat pointer, it also contains the length of the slice, which isn't included in the pointer. You need to use slice::from_raw_parts_mut for that. Additionally, since Box is an owned pointer, when the function returns it immediately gets dropped and the memory gets freed. You need to use a borrowed slice if you want the memory to stay allocated.