Is it possible for me to share data from the context of the linker into the state of a registered function?
For example:
fn register<T>(linker: Linker<T>) -> Result<()> {
let counter = opentelemetry::counter("some-count");
linker.func_wrap("my::module", "register", register)?; // Register function has no way of accessing the counter?
Ok(())
}
fn register<T>(caller: Caller<T>) {
// I want to access the counter from here to increment it
}
I'm considering using some kind of global state for this, but was wondering if there's a better way?
That's possible, yeah, because the argument to func_wrap
is a closure, but you'll probably find it more convenient to store such state within the T
of the Store<T>
as then you can avoid mutexes/locks/etc
Last updated: Dec 23 2024 at 14:03 UTC