title: Rust FFI. Casting to void pointer
body: <p>I've a function which has prototype as below</p>
  
  <pre><code>//opaque struct
  struct mosquitto;
  
  struct mosquitto *mosquitto_new(const char *id, bool clean_session, void *obj);
  </code></pre>
  
  <p>In my c code, I'm calling it as below.</p>
  
  <pre><code>struct mosquitto *m = mosquitto_new(buf, true, NULL);
  </code></pre>
  
  <p>Now I want to call the above API in my rust code. rust-bindgen generated the following bindings</p>
  
  <pre><code>pub enum Struct_mosquitto { }
  pub fn mosquitto_new(id: *const ::libc::c_char, clean_session: u8, obj: *mut ::libc::c_void) -&gt; *mut Struct_mosquitto;
  </code></pre>
  
  <p>When I'm trying to call the above API, I'm getting a mismatch at 3rd argument.</p>
  
  <pre><code>let s = CString::new("ravi").unwrap();
  let mqtt = mosquitto::mosquitto_new(s.as_ptr(), 1, ptr::null());
  </code></pre>
  
  <p>How do I pass NULL to *mut c_void?</p>
  
  <p><strong>BONUS QUESTION:</strong> How to pass a rust struct to *mut c_void ?</p>