Dealing with the unknown

C developers don't always pass parameters between functions that have strong types; rather, they pass a void* type. This is then cast to be something solid within the receiving function. In a way, this is very similar to passing a generic type between functions.

These have to be dealt with in a different way if you want to access a function within a library that has a void* as a parameter type.

For example, the C functions may be:

void output_data(void *data); 
void transformed_data(void *data); 

As we don't have anything in Rust the same as void*, we need to use a mutable pointer:

extern crate libc; 
extern "C" 
 { 
    pub fn output_data(arg: *mut libc::c_void); 
    pub fn transformed_data(arg: *mut libc::c_void); 
} 

This will do the job.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset