Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't mutate state from Funcs passed as wasm imports #1678

Closed
J0eCool opened this issue May 11, 2020 · 1 comment
Closed

Can't mutate state from Funcs passed as wasm imports #1678

J0eCool opened this issue May 11, 2020 · 1 comment

Comments

@J0eCool
Copy link

J0eCool commented May 11, 2020

Trying to build a graphical application using the wasmtime Rust API, using the sdl2 crate, I run in to the issue that SDL's drawing methods take a mutable reference to the screen, and using those from a closure passed to Func::wrap gives me the error

error[E0525]: expected a closure that implements the Fn trait, but this closure only implements FnMut

Feature

Let the closure argument to Func::wrap derive from FnMut instead of Fn

Benefit

This should allow embedder applications more freedom to build wasm modules that interact with the outside world in stateful ways

@alexcrichton
Copy link
Member

Thanks for the report! This is required for safety when using wasm modules, however, so it's not something that we can fix. Host functions can be called recursively if they, for example, reenter wasm and then get called again.

You can get mutation through interior mutability in Rust, however, for example through RefCell or Cell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants