abel-von opened issue #6712:
As if we want to use WASI, we will make the "data" as WasiCtx, and if we want to limit the resources, we have to call
limiterwith a function of Typeimpl FnMut(&mut T) -> &mut (dyn crate::ResourceLimiter) + Send + Sync + 'static. To satisfy this lifecycle requirement, we have to initialize an object of type that implements ResourceLimiter, and add it into thedataof Store, but as thedatais almost often to be aWasiCtx, we have no way to store this ResourceLimiter into it. That makes it no way to define a ResourceLimiter for those run wasm with wasi supported.
alexcrichton commented on issue #6712:
When using WASI the
TinStore<T>doesn't have to beWasiCtx, it only needs to containWasiCtx. This means you can do something like:struct MyData { wasi: WasiCtx, max_memory: usize, } impl ResourceLImiter for MyData { // ... }and then when you call
wasmtime_wasi::add_to_linkerthe closure would be|data| &mut data.wasi(or something along these lines).Does that work for your use case?
alexcrichton edited a comment on issue #6712:
When using WASI the
TinStore<T>doesn't have to beWasiCtx, it only needs to containWasiCtx. This means you can do something like:struct MyData { wasi: WasiCtx, max_memory: usize, } impl ResourceLimiter for MyData { // ... }and then when you call
wasmtime_wasi::add_to_linkerthe closure would be|data| &mut data.wasi(or something along these lines).Does that work for your use case?
abel-von commented on issue #6712:
Thank you for reply , I think it works for me.
abel-von closed issue #6712:
As if we want to use WASI, we will make the "data" as WasiCtx, and if we want to limit the resources, we have to call
limiterwith a function of Typeimpl FnMut(&mut T) -> &mut (dyn crate::ResourceLimiter) + Send + Sync + 'static. To satisfy this lifecycle requirement, we have to initialize an object of type that implements ResourceLimiter, and add it into thedataof Store, but as thedatais almost often to be aWasiCtx, we have no way to store this ResourceLimiter into it. That makes it no way to define a ResourceLimiter for those run wasm with wasi supported.
Last updated: Dec 13 2025 at 19:03 UTC