INNER CODE UNIT · Rust
allocate_guest_memory
lunatic-solutions/lunatic · crates/lunatic-common-api/src/lib.rs:18
pub fn allocate_guest_memory<'a, T: Send>(
caller: &'a mut Caller<T>,
size: u32,
) -> Pin<Box<dyn Future<Output = Result<u32>> + Send + 'a>> {
Box::pin(async move {
let mut results = [Val::I32(0)];
caller
.get_export(ALLOCATOR_FUNCTION_NAME)
.or_trap(format!("no export named {ALLOCATOR_FUNCTION_NAME} found"))?
.into_func()
.or_trap("cannot turn export into func")?
.call_async(caller, &[Val::I32(size as i32)], &mut results)
.await
.or_trap(format!("failed to call {ALLOCATOR_FUNCTION_NAME}"))?;
Ok(results[0]
.i32()
.or_trap(format!("result of {ALLOCATOR_FUNCTION_NAME} is not i32"))? as u32)