MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / from_val

Method from_val

crates/c-api/src/val.rs:83–120  ·  view source on GitHub ↗
(val: Val)

Source from the content-addressed store, hash-verified

81
82impl wasm_val_t {
83 pub fn from_val(val: Val) -> wasm_val_t {
84 match val {
85 Val::I32(i) => wasm_val_t {
86 kind: WASM_I32,
87 of: wasm_val_union { i32: i },
88 },
89 Val::I64(i) => wasm_val_t {
90 kind: WASM_I64,
91 of: wasm_val_union { i64: i },
92 },
93 Val::F32(f) => wasm_val_t {
94 kind: WASM_F32,
95 of: wasm_val_union { u32: f },
96 },
97 Val::F64(f) => wasm_val_t {
98 kind: WASM_F64,
99 of: wasm_val_union { u64: f },
100 },
101 #[cfg(feature = "gc")]
102 Val::FuncRef(f) => wasm_val_t {
103 kind: WASM_FUNCREF,
104 of: wasm_val_union {
105 ref_: f.map_or(ptr::null_mut(), |f| {
106 Box::into_raw(Box::new(wasm_ref_t {
107 r: Ref::Func(Some(f)),
108 }))
109 }),
110 },
111 },
112 #[cfg(not(feature = "gc"))]
113 Val::FuncRef(_) => crate::abort("creating a wasm_val_t from a funcref"),
114 Val::AnyRef(_) => crate::abort("creating a wasm_val_t from an anyref"),
115 Val::ExternRef(_) => crate::abort("creating a wasm_val_t from an externref"),
116 Val::ExnRef(_) => crate::abort("creating a wasm_val_t from an exnref"),
117 Val::V128(_) => crate::abort("creating a wasm_val_t from a v128"),
118 Val::ContRef(_) => crate::abort("creating a wasm_val_t from a contref"),
119 }
120 }
121
122 pub fn val(&self) -> Val {
123 match self.kind {

Callers

nothing calls this directly

Calls 3

abortFunction · 0.85
newFunction · 0.50
FuncClass · 0.50

Tested by

no test coverage detected