denoland / deno_bindgen

Write high-level Deno FFI libraries in Rust.
MIT License
274 stars 28 forks source link

Support for unsafe functions #143

Open nearest-river opened 8 months ago

nearest-river commented 8 months ago

Supporting unsafe functions for deno_bindgen would be so great as it'll eliminate the need to use an unsafe block when using pointers which is pretty annoying...

Now

#[deno_bindgen]
pub fn some_method(ptr: usize) {
  unsafe {
    let this=(ptr as *const SomeStruct).as_ref().unwrap();
    this.some_method();
  }
}

Better one

#[deno_bindgen]
pub unsafe fn some_method(ptr: usize) {
  let this=(ptr as *const SomeStruct).as_ref().unwrap();
  this.some_method();
}