xref: /wasmtime-44.0.1/crates/c-api/src/tag.rs (revision 0dbb6f3d)
1 use crate::{
2     WasmtimeStoreContext, WasmtimeStoreContextMut, handle_result, wasm_tagtype_t, wasmtime_error_t,
3 };
4 use std::mem::MaybeUninit;
5 use wasmtime::Tag;
6 
7 /// Creates a new host-defined tag with the given type.
8 #[unsafe(no_mangle)]
wasmtime_tag_new( mut store: WasmtimeStoreContextMut<'_>, tt: &wasm_tagtype_t, ret: &mut MaybeUninit<Tag>, ) -> Option<Box<wasmtime_error_t>>9 pub unsafe extern "C" fn wasmtime_tag_new(
10     mut store: WasmtimeStoreContextMut<'_>,
11     tt: &wasm_tagtype_t,
12     ret: &mut MaybeUninit<Tag>,
13 ) -> Option<Box<wasmtime_error_t>> {
14     let tag_type = tt.to_tag_type(store.engine());
15     handle_result(Tag::new(&mut store, &tag_type), |tag| {
16         ret.write(tag);
17     })
18 }
19 
20 /// Returns the type of this tag.
21 #[unsafe(no_mangle)]
wasmtime_tag_type( store: WasmtimeStoreContext<'_>, tag: &Tag, ) -> Box<wasm_tagtype_t>22 pub extern "C" fn wasmtime_tag_type(
23     store: WasmtimeStoreContext<'_>,
24     tag: &Tag,
25 ) -> Box<wasm_tagtype_t> {
26     let ty = tag.ty(store);
27     Box::new(wasm_tagtype_t::from_tag_type(ty))
28 }
29 
30 /// Tests whether two tags are the same (identity equality).
31 #[unsafe(no_mangle)]
wasmtime_tag_eq(store: WasmtimeStoreContext<'_>, a: &Tag, b: &Tag) -> bool32 pub extern "C" fn wasmtime_tag_eq(store: WasmtimeStoreContext<'_>, a: &Tag, b: &Tag) -> bool {
33     Tag::eq(a, b, store)
34 }
35