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

Function wasmtime_structref_new

crates/c-api/src/structref.rs:27–50  ·  view source on GitHub ↗
(
    mut cx: WasmtimeStoreContextMut<'_>,
    pre: &wasmtime_struct_ref_pre_t,
    fields: *const crate::wasmtime_val_t,
    nfields: usize,
    out: &mut MaybeUninit<wasmtime_structref_t>,
)

Source from the content-addressed store, hash-verified

25
26#[unsafe(no_mangle)]
27pub unsafe extern "C" fn wasmtime_structref_new(
28 mut cx: WasmtimeStoreContextMut<'_>,
29 pre: &wasmtime_struct_ref_pre_t,
30 fields: *const crate::wasmtime_val_t,
31 nfields: usize,
32 out: &mut MaybeUninit<wasmtime_structref_t>,
33) -> Option<Box<crate::wasmtime_error_t>> {
34 let c_fields = crate::slice_from_raw_parts(fields, nfields);
35 let mut scope = RootScope::new(&mut cx);
36 let vals: Vec<Val> = c_fields.iter().map(|v| v.to_val(&mut scope)).collect();
37 match StructRef::new(&mut scope, &pre.pre, &vals) {
38 Ok(structref) => {
39 let owned = structref
40 .to_owned_rooted(&mut scope)
41 .expect("just allocated");
42 crate::initialize(out, Some(owned).into());
43 None
44 }
45 Err(e) => {
46 crate::initialize(out, None::<OwnedRooted<StructRef>>.into());
47 Some(Box::new(e.into()))
48 }
49 }
50}
51
52#[unsafe(no_mangle)]
53pub unsafe extern "C" fn wasmtime_structref_to_anyref(

Callers 1

createMethod · 0.85

Calls 9

slice_from_raw_partsFunction · 0.85
collectMethod · 0.80
to_valMethod · 0.80
initializeFunction · 0.70
newFunction · 0.50
mapMethod · 0.45
iterMethod · 0.45
expectMethod · 0.45
to_owned_rootedMethod · 0.45

Tested by

no test coverage detected