1 use crate::wasmtime_component_valtype_t;
2 use std::mem::MaybeUninit;
3 use wasmtime::component::types::ComponentFunc;
4
5 type_wrapper! {
6 pub struct wasmtime_component_func_type_t {
7 pub(crate) ty: ComponentFunc,
8 }
9
10 clone: wasmtime_component_func_type_clone,
11 delete: wasmtime_component_func_type_delete,
12 }
13
14 #[unsafe(no_mangle)]
wasmtime_component_func_type_async(ty: &wasmtime_component_func_type_t) -> bool15 pub extern "C" fn wasmtime_component_func_type_async(ty: &wasmtime_component_func_type_t) -> bool {
16 ty.ty.async_()
17 }
18
19 #[unsafe(no_mangle)]
wasmtime_component_func_type_param_count( ty: &wasmtime_component_func_type_t, ) -> usize20 pub extern "C" fn wasmtime_component_func_type_param_count(
21 ty: &wasmtime_component_func_type_t,
22 ) -> usize {
23 ty.ty.params().len()
24 }
25
26 #[unsafe(no_mangle)]
wasmtime_component_func_type_param_nth( ty: &wasmtime_component_func_type_t, nth: usize, name_ret: &mut MaybeUninit<*const u8>, name_len_ret: &mut MaybeUninit<usize>, type_ret: &mut MaybeUninit<wasmtime_component_valtype_t>, ) -> bool27 pub unsafe extern "C" fn wasmtime_component_func_type_param_nth(
28 ty: &wasmtime_component_func_type_t,
29 nth: usize,
30 name_ret: &mut MaybeUninit<*const u8>,
31 name_len_ret: &mut MaybeUninit<usize>,
32 type_ret: &mut MaybeUninit<wasmtime_component_valtype_t>,
33 ) -> bool {
34 match ty.ty.params().nth(nth) {
35 Some((name, item)) => {
36 let name: &str = name;
37 name_ret.write(name.as_ptr());
38 name_len_ret.write(name.len());
39 type_ret.write(item.into());
40 true
41 }
42 None => false,
43 }
44 }
45 #[unsafe(no_mangle)]
wasmtime_component_func_type_result( ty: &wasmtime_component_func_type_t, type_ret: &mut MaybeUninit<wasmtime_component_valtype_t>, ) -> bool46 pub extern "C" fn wasmtime_component_func_type_result(
47 ty: &wasmtime_component_func_type_t,
48 type_ret: &mut MaybeUninit<wasmtime_component_valtype_t>,
49 ) -> bool {
50 let len = ty.ty.results().len();
51 assert!(len <= 1);
52 match ty.ty.results().next() {
53 Some(item) => {
54 type_ret.write(item.into());
55 true
56 }
57 None => false,
58 }
59 }
60