xref: /wasmtime-44.0.1/crates/c-api/src/component/instance.rs (revision 4c8edb95)
  • Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use wasmtime::component::{Func, Instance};
2 
3 use crate::WasmtimeStoreContextMut;
4 
5 use super::wasmtime_component_export_index_t;
6 
7 #[unsafe(no_mangle)]
8 pub 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)]
32 pub 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 }
45 

served by {OpenGrok

Last Index Update: Fri May 15 20:09:11 GMT 2026