deno_bindgen icon indicating copy to clipboard operation
deno_bindgen copied to clipboard

implement `impl` as classes

Open littledivy opened this issue 2 years ago • 0 comments

Doable with Box<T>. Reference/Mutable reference for methods and deallocate box when consumed/finalization

pub struct NonSerializable {
  inner: i32,
}

#[deno_bindgen]
impl NonSerializable {
  pub fn add(&mut self, a: i32) {
    self.inner += a;
  }
  
  #[deno_bindgen(constructor)]
  pub fn new() -> Self {
    Self { inner: 0 }
  }
}
const ptr = new NonSerializable();
ptr.add(10)

littledivy avatar Mar 13 '22 17:03 littledivy