wasmtime_c_api/types/
exn.rs1use crate::{wasm_tagtype_t, wasm_valtype_vec_t, wasmtime_error_t};
2use std::mem::MaybeUninit;
3use wasmtime::ExnType;
4
5#[derive(Clone)]
6pub struct wasmtime_exn_type_t {
7 pub(crate) ty: ExnType,
8}
9wasmtime_c_api_macros::declare_ty!(wasmtime_exn_type_t);
10
11impl From<ExnType> for wasmtime_exn_type_t {
12 fn from(ty: ExnType) -> Self {
13 Self { ty }
14 }
15}
16
17#[unsafe(no_mangle)]
18pub extern "C" fn wasmtime_exn_type_new(
19 engine: &crate::wasm_engine_t,
20 params: &wasm_valtype_vec_t,
21 out: &mut MaybeUninit<Box<wasmtime_exn_type_t>>,
22) -> Option<Box<wasmtime_error_t>> {
23 crate::handle_result(
24 ExnType::new(
25 &engine.engine,
26 params
27 .as_slice()
28 .iter()
29 .map(|t| (**t.as_ref().unwrap()).clone()),
30 ),
31 |ty| {
32 out.write(Box::new(wasmtime_exn_type_t { ty }));
33 },
34 )
35}
36
37#[unsafe(no_mangle)]
38pub extern "C" fn wasmtime_exn_type_tag_type(ty: &wasmtime_exn_type_t) -> Box<wasm_tagtype_t> {
39 Box::new(wasm_tagtype_t::new(ty.ty.tag_type()))
40}