Rust FFI. Casting to void pointer -


i've function has prototype below

//opaque struct struct mosquitto;  struct mosquitto *mosquitto_new(const char *id, bool clean_session, void *obj); 

in c code, i'm calling below.

struct mosquitto *m = mosquitto_new(buf, true, null); 

now want call above api in rust code. rust-bindgen generated following bindings

pub enum struct_mosquitto { } pub fn mosquitto_new(id: *const ::libc::c_char, clean_session: u8, obj: *mut ::libc::c_void) -> *mut struct_mosquitto; 

when i'm trying call above api, i'm getting mismatch @ 3rd argument.

let s = cstring::new("ravi").unwrap(); let mqtt = mosquitto::mosquitto_new(s.as_ptr(), 1, ptr::null()); 

how pass null *mut c_void?

bonus question: how pass rust struct *mut c_void ?

the ptr::null() function returns *const t, want ptr::null_mut() function, since argument function of type *mut ::libc::c_void.

for passing actual value, have @ answer working c_void in ffi


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -