Skip to content

FromWasmAbi is not implemented for fn(SomeStruct) , while SomeStruct is #[wasm_bindgen] #1092

Open
@venil7

Description

@venil7

Basically I have a 3 structs and two types defined

type OnMoveEvent = fn(Board) -> ();
type OnGameOverEvent = fn(Player) -> ();

#[wasm_bindgen]
pub struct Game {
  on_move: OnMoveEvent,
  on_game_over: OnGameOverEvent,
  board: Board,
}
#[wasm_bindgen]
pub struct Board { .. }
#[wasm_bindgen]
pub struct Player { .. }

All 3 structs are wasm_bindgen and types can not be marked as wasm_bindgen. However types are just functions accepting structs and returning void

When I add wasm_bindgen to Game impl I get the following error

 --> src/game.rs:16:1
     |
  16 | #[wasm_bindgen]
     | ^^^^^^^^^^^^^^^ the trait `wasm_bindgen::convert::traits::FromWasmAbi` is not implemented for `fn(board::Board)`

That is because new has the following signature

  pub fn new(on_move: OnMoveEvent, on_game_over: OnGameOverEvent) -> Game {

It seemed to me that it should be simple to translate types as they are functions accepting wasm_bindgen structs, but it appears as it's not the case

Is this a bug or am I missing something

full code is here

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsIssues related to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions