J0eCool opened Issue #1678:
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 errorerror[E0525]: expected a closure that implements the
Fn
trait, but this closure only implementsFnMut
Feature
Let the closure argument to
Func::wrap
derive fromFnMut
instead ofFn
Benefit
This should allow embedder applications more freedom to build wasm modules that interact with the outside world in stateful ways
alexcrichton commented on Issue #1678:
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
orCell
.
alexcrichton closed Issue #1678:
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 errorerror[E0525]: expected a closure that implements the
Fn
trait, but this closure only implementsFnMut
Feature
Let the closure argument to
Func::wrap
derive fromFnMut
instead ofFn
Benefit
This should allow embedder applications more freedom to build wasm modules that interact with the outside world in stateful ways
Last updated: Dec 23 2024 at 12:05 UTC