jlkiri opened issue #4138:
I am struggling with applying a limiter to the wasmtime store by using the
limiter
API.Here's the code I have.
let engine = Engine::default(); let module = Module::new(&engine, module_bytes)?; let store_limits = StoreLimits::default(); let mut store = Store::new(&engine, ()); store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
It doesn't compile and gives me the error:
error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements --> src/handler.rs:140:45 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^ | note: first, the lifetime cannot outlive the lifetime `'_` as defined here... --> src/handler.rs:140:19 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...so that closure can access `store_limits` --> src/handler.rs:140:45 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^ note: but, the lifetime must be valid for the anonymous lifetime #1 defined here... --> src/handler.rs:140:19 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...so that the declared lifetime parameter bounds are satisfied --> src/handler.rs:140:35 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ For more information about this error, try `rustc --explain E0495`.
I know that my usage might be wrong but I just can't make it work so I would appreciate an example.
jlkiri edited issue #4138:
I am struggling with applying a limiter to the wasmtime store by using the
limiter
API.Here's the code I have.
let engine = Engine::default(); let module = Module::new(&engine, module_bytes)?; let store_limits = StoreLimits::default(); let mut store = Store::new(&engine, ()); store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
It doesn't compile and gives me the error:
error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements --> src/handler.rs:140:45 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^ | note: first, the lifetime cannot outlive the lifetime `'_` as defined here... --> src/handler.rs:140:19 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...so that closure can access `store_limits` --> src/handler.rs:140:45 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^ note: but, the lifetime must be valid for the anonymous lifetime #1 defined here... --> src/handler.rs:140:19 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...so that the declared lifetime parameter bounds are satisfied --> src/handler.rs:140:35 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ For more information about this error, try `rustc --explain E0495`.
I know that my usage might be wrong but I just can't make it work so I would appreciate an example.
jlkiri edited issue #4138:
I am struggling with applying a limiter to the wasmtime store by using the
limiter
API.Here's the code I have.
let engine = Engine::default(); let module = Module::new(&engine, module_bytes)?; let store_limits = StoreLimits::default(); let mut store = Store::new(&engine, ()); store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
StoreLimits is wasmtime's [
StoreLimits
](https://docs.rs/wasmtime/0.36.0/wasmtime/struct.StoreLimits.html
It doesn't compile and gives me the error:error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements --> src/handler.rs:140:45 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^ | note: first, the lifetime cannot outlive the lifetime `'_` as defined here... --> src/handler.rs:140:19 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...so that closure can access `store_limits` --> src/handler.rs:140:45 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^ note: but, the lifetime must be valid for the anonymous lifetime #1 defined here... --> src/handler.rs:140:19 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...so that the declared lifetime parameter bounds are satisfied --> src/handler.rs:140:35 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ For more information about this error, try `rustc --explain E0495`.
I know that my usage might be wrong but I just can't make it work so I would appreciate an example.
jlkiri edited issue #4138:
I am struggling with applying a limiter to the wasmtime store by using the
limiter
API.Here's the code I have.
let engine = Engine::default(); let module = Module::new(&engine, module_bytes)?; let store_limits = StoreLimits::default(); let mut store = Store::new(&engine, ()); store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
StoreLimits is wasmtime's
StoreLimits
It doesn't compile and gives me the error:error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements --> src/handler.rs:140:45 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^ | note: first, the lifetime cannot outlive the lifetime `'_` as defined here... --> src/handler.rs:140:19 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...so that closure can access `store_limits` --> src/handler.rs:140:45 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^ note: but, the lifetime must be valid for the anonymous lifetime #1 defined here... --> src/handler.rs:140:19 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...so that the declared lifetime parameter bounds are satisfied --> src/handler.rs:140:35 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ For more information about this error, try `rustc --explain E0495`.
I know that my usage might be wrong but I just can't make it work so I would appreciate an example.
jlkiri edited issue #4138:
I am struggling with applying a limiter to the wasmtime store by using the
limiter
API.Here's the code I have.
let engine = Engine::default(); let module = Module::new(&engine, module_bytes)?; let store_limits = StoreLimits::default(); let mut store = Store::new(&engine, ()); store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
StoreLimits is wasmtime's
StoreLimits
. It doesn't compile and gives me the error:error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements --> src/handler.rs:140:45 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^ | note: first, the lifetime cannot outlive the lifetime `'_` as defined here... --> src/handler.rs:140:19 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...so that closure can access `store_limits` --> src/handler.rs:140:45 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^ note: but, the lifetime must be valid for the anonymous lifetime #1 defined here... --> src/handler.rs:140:19 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...so that the declared lifetime parameter bounds are satisfied --> src/handler.rs:140:35 | 140 | store.limiter(|data: &mut ()| lim(data, &mut store_limits)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ For more information about this error, try `rustc --explain E0495`.
I know that my usage might be wrong but I just can't make it work so I would appreciate an example.
jlkiri edited issue #4138:
I am struggling with applying a limiter to the wasmtime store by using the
limiter
API.Here's the code I have.
let engine = Engine::default(); let module = Module::new(&engine, module_bytes)?; let store_limits = StoreLimits::default(); let mut store = Store::new(&engine, ()); store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
StoreLimits is wasmtime's
StoreLimits
. It doesn't compile and gives me the error:error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements --> src/handler.rs:139:23 | 139 | store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter); | ^^^^^^^^^^^^^^^^^ | note: first, the lifetime cannot outlive the lifetime `'_` as defined here... --> src/handler.rs:139:19 | 139 | store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...so that closure can access `store_limits` --> src/handler.rs:139:23 | 139 | store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter); | ^^^^^^^^^^^^^^^^^ note: but, the lifetime must be valid for the anonymous lifetime #1 defined here... --> src/handler.rs:139:19 | 139 | store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...so that the types are compatible --> src/handler.rs:139:23 | 139 | store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: expected `&mut dyn wasmtime::ResourceLimiter` found `&mut dyn wasmtime::ResourceLimiter` For more information about this error, try `rustc --explain E0495`.
I know that my usage might be wrong but I just can't make it work so I would appreciate an example.
jlkiri commented on issue #4138:
Why can't the API just take StoreLimits itself?
jlkiri edited a comment on issue #4138:
Why can't the API just take StoreLimits itself, direcly?
jlkiri edited a comment on issue #4138:
Why can't the API just take an owned / reference of StoreLimits itself, direcly?
bjorn3 commented on issue #4138:
I believe you are supposed to store the
ResourceLimiter
implementation in theStore
state and then return a reference to it from the closure you pass tolimiter
.
alexcrichton commented on issue #4138:
Indeed the limits are intended to live within the
T
of the store, and the main reason for this is to avoid plumbing a genericU
for the limiter everywhere in wasmtime. When working withdyn
trait objects in this case the closure can't returnimpl ResourceLimiter
or something like that.I think the documentation could be improved here, though, with better examples and more words about how to use the API for sure!
alexcrichton labeled issue #4138:
I am struggling with applying a limiter to the wasmtime store by using the
limiter
API.Here's the code I have.
let engine = Engine::default(); let module = Module::new(&engine, module_bytes)?; let store_limits = StoreLimits::default(); let mut store = Store::new(&engine, ()); store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
StoreLimits is wasmtime's
StoreLimits
. It doesn't compile and gives me the error:error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements --> src/handler.rs:139:23 | 139 | store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter); | ^^^^^^^^^^^^^^^^^ | note: first, the lifetime cannot outlive the lifetime `'_` as defined here... --> src/handler.rs:139:19 | 139 | store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...so that closure can access `store_limits` --> src/handler.rs:139:23 | 139 | store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter); | ^^^^^^^^^^^^^^^^^ note: but, the lifetime must be valid for the anonymous lifetime #1 defined here... --> src/handler.rs:139:19 | 139 | store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...so that the types are compatible --> src/handler.rs:139:23 | 139 | store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: expected `&mut dyn wasmtime::ResourceLimiter` found `&mut dyn wasmtime::ResourceLimiter` For more information about this error, try `rustc --explain E0495`.
I know that my usage might be wrong but I just can't make it work so I would appreciate an example.
github-actions[bot] commented on issue #4138:
Subscribe to Label Action
cc @peterhuene
<details>
This issue or pull request has been labeled: "wasmtime:api"Thus the following users have been cc'd because of the following labels:
- peterhuene: wasmtime:api
To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.
Learn more.
</details>
jlkiri commented on issue #4138:
@alexcrichton @bjorn3 Thanks! Putting the limiter in the store solved the problem
jlkiri edited a comment on issue #4138:
@alexcrichton @bjorn3 Thanks! Putting the limiter in the store solved the immediate problem
alexcrichton closed issue #4138:
I am struggling with applying a limiter to the wasmtime store by using the
limiter
API.Here's the code I have.
let engine = Engine::default(); let module = Module::new(&engine, module_bytes)?; let store_limits = StoreLimits::default(); let mut store = Store::new(&engine, ()); store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
StoreLimits is wasmtime's
StoreLimits
. It doesn't compile and gives me the error:error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements --> src/handler.rs:139:23 | 139 | store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter); | ^^^^^^^^^^^^^^^^^ | note: first, the lifetime cannot outlive the lifetime `'_` as defined here... --> src/handler.rs:139:19 | 139 | store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...so that closure can access `store_limits` --> src/handler.rs:139:23 | 139 | store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter); | ^^^^^^^^^^^^^^^^^ note: but, the lifetime must be valid for the anonymous lifetime #1 defined here... --> src/handler.rs:139:19 | 139 | store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...so that the types are compatible --> src/handler.rs:139:23 | 139 | store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: expected `&mut dyn wasmtime::ResourceLimiter` found `&mut dyn wasmtime::ResourceLimiter` For more information about this error, try `rustc --explain E0495`.
I know that my usage might be wrong but I just can't make it work so I would appreciate an example.
Last updated: Nov 22 2024 at 16:03 UTC