wasmtime_c_api/component/
instance.rs1use wasmtime::component::{Func, Instance};
2
3use crate::WasmtimeStoreContextMut;
4
5use super::wasmtime_component_export_index_t;
6
7#[unsafe(no_mangle)]
8pub unsafe extern "C" fn wasmtime_component_instance_get_export_index(
9 instance: &Instance,
10 context: WasmtimeStoreContextMut<'_>,
11 instance_export_index: *const wasmtime_component_export_index_t,
12 name: *const u8,
13 name_len: usize,
14) -> Option<Box<wasmtime_component_export_index_t>> {
15 let name = unsafe { std::slice::from_raw_parts(name, name_len) };
16 let Ok(name) = std::str::from_utf8(name) else {
17 return None;
18 };
19
20 let instance_export_index = if instance_export_index.is_null() {
21 None
22 } else {
23 Some((*instance_export_index).export_index)
24 };
25
26 instance
27 .get_export_index(context, instance_export_index.as_ref(), &name)
28 .map(|export_index| Box::new(wasmtime_component_export_index_t { export_index }))
29}
30
31#[unsafe(no_mangle)]
32pub unsafe extern "C" fn wasmtime_component_instance_get_func(
33 instance: &Instance,
34 context: WasmtimeStoreContextMut<'_>,
35 export_index: &wasmtime_component_export_index_t,
36 func_out: &mut Func,
37) -> bool {
38 if let Some(func) = instance.get_func(context, export_index.export_index) {
39 *func_out = func;
40 true
41 } else {
42 false
43 }
44}