pub fn write_region(ctx: &Ctx, ptr: u32, data: &[u8]) -> VmResult<()> {
    let mut region = get_region(ctx, ptr)?;

    let region_capacity = region.capacity as usize;
    if data.len() > region_capacity {
        return Err(CommunicationError::region_too_small(region_capacity, data.len()).into());
    }

    let memory = ctx.memory(0);
    match WasmPtr::<u8, Array>::new(region.offset).deref(memory, 0, region.capacity) {
        Some(cells) => {
            // In case you want to do some premature optimization, this shows how to cast a `&'mut [Cell<u8>]` to `&mut [u8]`:
            // https://github.com/wasmerio/wasmer/blob/0.13.1/lib/wasi/src/syscalls/mod.rs#L79-L81
            for i in 0..data.len() {
                cells[i].set(data[i])
            }
            region.length = data.len() as u32;
            set_region(ctx, ptr, region)?;
            Ok(())
        },
        None => Err(CommunicationError::deref_err(region.offset, format!(
            "Tried to access memory of region {:?} in wasm memory of size {} bytes. This typically happens when the given Region pointer does not point to a proper Region struct.",
            region,
            memory.size().bytes().0
        )).into()),
    }
}
/// A prepared and sufficiently large memory Region is expected at ptr that points to pre-allocated memory.
///
/// Returns number of bytes written on success.
A prepared and sufficiently large memory Region is expected at ptr that points to pre-allocated memory.
Returns number of bytes written on success.
A prepared and sufficiently large memory Region is expected at ptr that points to pre - allocated memory . Returns number of bytes written on success .
pub fn write_region(ctx: &Ctx, ptr: u32, data: &[u8]) -> VmResult<()> {
    let mut region = get_region(ctx, ptr)?;
    let region_capacity = region.capacity as usize;
    if data.len() > region_capacity {
        return Err(CommunicationError::region_too_small(region_capacity, data.len()).into());
    }
    let memory = ctx.memory(0);
    match WasmPtr::<u8, Array>::new(region.offset).deref(memory, 0, region.capacity) {
        Some(cells) => {
            // In case you want to do some premature optimization, this shows how to cast a `&'mut [Cell<u8>]` to `&mut [u8]`:
            // https://github.com/wasmerio/wasmer/blob/0.13.1/lib/wasi/src/syscalls/mod.rs#L79-L81
            for i in 0..data.len() {
                cells[i].set(data[i])
            }
            region.length = data.len() as u32;
            set_region(ctx, ptr, region)?;
            Ok(())
        },
        None => Err(CommunicationError::deref_err(region.offset, format!(
            "Tried to access memory of region {:?} in wasm memory of size {} bytes. This typically happens when the given Region pointer does not point to a proper Region struct.",
            region,
            memory.size().bytes().0
        )).into()),
    }
}
pub fn write_region ( ctx : & Ctx , ptr : u32 , data : & [ u8 ] ) -> VmResult < ( ) > { let mut region = get_region ( ctx , ptr ) ? ; let region_capacity = region . capacity as usize ; if data . len ( ) > region_capacity { return Err ( CommunicationError :: region_too_small ( region_capacity , data . len ( ) ) . into ( ) ) ; } let memory = ctx . memory ( 0 ) ; match WasmPtr :: < u8 , Array > :: new ( region . offset ) . deref ( memory , 0 , region . capacity ) { Some ( cells ) => { // In case you want to do some premature optimization, this shows how to cast a `&'mut [Cell<u8>]` to `&mut [u8]`: // https://github.com/wasmerio/wasmer/blob/0.13.1/lib/wasi/src/syscalls/mod.rs#L79-L81 for i in 0 .. data . len ( ) { cells [ i ] . set ( data [ i ] ) } region . length = data . len ( ) as u32 ; set_region ( ctx , ptr , region ) ? ; Ok ( ( ) ) } , None => Err ( CommunicationError :: deref_err ( region . offset , format ! ( " " region memory size ( ) bytes ( ) 0 ) ) . into ( ) ) , } }
A prepared and sufficiently large memory Region is expected at ptr that points to pre-allocated memory.
A prepared and sufficiently large memory Region is expected at ptr that points to pre - allocated memory .
ctx
&Ctx
ptr
u32
data
&[u8]
ctx
&Ctx
ptr
u32
data
&[u8]