Skip to main content

fluvio_smartstream/
lib.rs

1#![doc = include_str!("../README.md")]
2
3pub use fluvio_dataplane_protocol as dataplane;
4pub use dataplane::record::{Record, RecordData};
5
6#[cfg(feature = "derive")]
7pub use fluvio_smartstream_derive::{smartstream, SmartOpt};
8
9pub const ENCODING_ERROR: i32 = -1;
10
11pub use eyre::Error;
12pub type Result<T> = eyre::Result<T>;
13
14pub mod memory {
15    /// Allocate memory into the module's linear memory
16    /// and return the offset to the start of the block.
17    #[no_mangle]
18    pub fn alloc(len: usize) -> *mut u8 {
19        // create a new mutable buffer with capacity `len`
20        let mut buf = Vec::with_capacity(len);
21        // take a mutable pointer to the buffer
22        let ptr = buf.as_mut_ptr();
23        // take ownership of the memory block and
24        // ensure the its destructor is not
25        // called when the object goes out of scope
26        // at the end of the function
27        std::mem::forget(buf);
28        // return the pointer so the runtime
29        // can write data at this offset
30        ptr
31    }
32
33    #[no_mangle]
34    #[allow(clippy::missing_safety_doc)]
35    pub unsafe fn dealloc(ptr: *mut u8, size: usize) {
36        let data = Vec::from_raw_parts(ptr, size, size);
37        std::mem::drop(data);
38    }
39}