Stream: wasmtime

Topic: instance name


view this post on Zulip Ludea (Mar 10 2026 at 15:31):

Hi, I use https://docs.rs/wasmtime/latest/wasmtime/component/struct.Instance.html#method.get_export_index
to get instance index and to call an exported fn from interface.
For now, I hardocoded the instance name (third arg) , but can we get instance name instead ?

view this post on Zulip Alex Crichton (Mar 10 2026 at 15:34):

Can you expand a bit more on your use case? You say you hardcoded an instance name, but then also asked how you can get the instance name, and I'm not quite sure what you mean by that?

view this post on Zulip Ludea (Mar 10 2026 at 15:37):

For now I call https://docs.rs/wasmtime/latest/wasmtime/component/struct.Instance.html#method.get_export_index with harcoded name.
I would like to avoid that and get instance name.

let instance = linker.instantiate_async(&mut store, &component).await?;
let instance_name = instance.name() //something like that

view this post on Zulip Joel Dice (Mar 10 2026 at 15:56):

Component instances don't inherently have names. An instance can export zero or more instances, each of which will have its own name. Are you perhaps asking to get a list of exports (e.g. as an array of (name, index) pairs) from an instance?

view this post on Zulip Ludea (Mar 10 2026 at 16:19):

Joel Dice said:

Component instances don't inherently have names. An instance can export zero or more instances, each of which will have its own name. Are you perhaps asking to get a list of exports (e.g. as an array of (name, index) pairs) from an instance?

I already do this :
https://github.com/bytecodealliance/wasmtime/blob/main/tests/all/component_model/func.rs#L3646 (as Joel already show me)
"i" is hardcoded too in this test.
I instanciate with linker. And I have to do mycomponent:package#myinterface@0.1.0
Instead of that, at least can we list instance and get their name?

view this post on Zulip Alex Crichton (Mar 10 2026 at 16:24):

To list exports what you'll want to do is have a Component, call Component::component_type, and then use types::Component::exports to get an iterator


Last updated: Mar 23 2026 at 18:16 UTC