Wasm_bindgen :: arguments cannot be `self`

pub trait Rust_Handle_Trait {
    fn resize(&self, width: u32, height: u32);
}

#[crate::wasm_bindgen::prelude::wasm_bindgen]
pub struct Rust_Handle_Js {
    handle: Rc<dyn Rust_Handle_Trait>,}

impl Rust_Handle_Js {
    pub fn new(t: Rc<dyn Rust_Handle_Trait>) -> Rust_Handle_Js {
        Rust_Handle_Js { handle: r}}}

#[crate::wasm_bindgen::prelude::wasm_bindgen]
impl Rust_Handle_Js {
    #[crate::wasm_bindgen::prelude::wasm_bindgen]
    pub fn resize(&self, width: u32, height: u32) {
        self.handle.resize(width, height);}}

wasm_bindgen seems to dislike the &self in the pub fn resize.

Questions:

  1. I don't understand what the problem is. The struct itself is #[wasm_bindgen]

  2. How do I get around this issue?

I'm curious why you have two identical bindgen attributes, one for resize and one for the outer impl block. I haven't tested the code but that looks wrong to me. The inner bindgen shouldn't be there.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.