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 ?
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?
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
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?
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?
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