MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / get_func

Method get_func

crates/wasmtime/src/runtime/component/instance.rs:155–171  ·  view source on GitHub ↗

Looks up an exported function by name within this [`Instance`]. The `store` argument provided must be the store that this instance lives within and the `name` argument is the lookup key by which to find the exported function. If the function is found then `Some` is returned and otherwise `None` is returned. The `name` here can be a string such as `&str` or it can be a [`ComponentExportIndex`] wh

(&self, mut store: impl AsContextMut, name: impl ExportLookup)

Source from the content-addressed store, hash-verified

153 /// # }
154 /// ```
155 pub fn get_func(&self, mut store: impl AsContextMut, name: impl ExportLookup) -> Option<Func> {
156 let store = store.as_context_mut().0;
157 let instance = self.id.get(store);
158 let component = instance.component();
159
160 // Validate that `name` exists within `self.`
161 let index = name.lookup(component, None)?;
162
163 // Validate that `index` is indeed a lifted function.
164 match &component.env_component().export_items[index] {
165 Export::LiftedFunction { .. } => {}
166 _ => return None,
167 }
168
169 // And package up the indices!
170 Some(Func::from_lifted_func(*self, index))
171 }
172
173 /// Looks up an exported [`Func`] value by name and with its type.
174 ///

Callers 1

get_typed_funcMethod · 0.45

Calls 5

env_componentMethod · 0.80
as_context_mutMethod · 0.45
getMethod · 0.45
componentMethod · 0.45
lookupMethod · 0.45

Tested by

no test coverage detected