with_read_on_stack_or_heap

Function with_read_on_stack_or_heap 

Source
pub fn with_read_on_stack_or_heap<T>(
    f: impl FnOnce(Result<&mut [u8], Error>) -> T,
) -> T
Expand description

Executes function f with provided message payload allocated on stack. If payload size is bigger than stack_buffer::MAX_BUFFER_SIZE, then allocation will be on heap.

Returns function f call result T.

ยงExamples

use gcore::msg;

#[unsafe(no_mangle)]
extern "C" fn handle() {
    msg::with_read_on_stack_or_heap(|read_res| {
        let payload: &mut [u8] = read_res.expect("Unable to read");
        // do something with `payload`
    });
}