MCPcopy Create free account
hub / github.com/explodingcamera/tinywasm / attach_type

Method attach_type

crates/tinywasm/src/interpreter/values.rs:98–112  ·  view source on GitHub ↗

Attaches a type to the value (panics if the size of the value is not the same as the type)

(self, ty: WasmType)

Source from the content-addressed store, hash-verified

96
97 /// Attaches a type to the value (panics if the size of the value is not the same as the type)
98 pub fn attach_type(self, ty: WasmType) -> Option<WasmValue> {
99 match (self, ty) {
100 (Self::Value32(v), WasmType::I32) => Some(WasmValue::I32(v as i32)),
101 (Self::Value64(v), WasmType::I64) => Some(WasmValue::I64(v as i64)),
102 (Self::Value32(v), WasmType::F32) => Some(WasmValue::F32(f32::from_bits(v))),
103 (Self::Value64(v), WasmType::F64) => Some(WasmValue::F64(f64::from_bits(v))),
104 (Self::ValueRef(v), WasmType::RefExtern) => Some(WasmValue::RefExtern(ExternRef::from_raw(v.raw()))),
105 (Self::ValueRef(v), WasmType::RefFunc) => Some(WasmValue::RefFunc(FuncRef::from_raw(v.raw()))),
106 (Self::Value128(v), WasmType::V128) => Some(WasmValue::V128(v.0)),
107 (_, WasmType::I32 | WasmType::F32) => None,
108 (_, WasmType::I64 | WasmType::F64) => None,
109 (_, WasmType::RefExtern | WasmType::RefFunc) => None,
110 (_, WasmType::V128) => None,
111 }
112 }
113}
114
115impl From<&WasmValue> for TinyWasmValue {

Callers 1

getMethod · 0.80

Calls 1

rawMethod · 0.45

Tested by

no test coverage detected