scotch_guest/
lib.rs

1#![no_std]
2
3/// Pointer size. Can be `u32` or `u64`.
4#[cfg(not(feature = "mem64"))]
5pub type MemoryType = u32;
6
7/// Pointer size. Can be `u32` or `u64`.
8#[cfg(feature = "mem64")]
9pub type MemoryType = u64;
10
11type PrefixType = u16;
12
13mod encoded;
14pub use encoded::*;
15
16mod managed;
17pub use managed::*;
18
19pub use scotch_guest_macros::*;
20
21/// Includes allocation utils for the host. Plugin will not work without it.
22/// You need to put it somewhere in your plugin crate.
23#[macro_export]
24macro_rules! export_alloc {
25    () => {
26        #[no_mangle]
27        extern "C" fn __scotch_alloc(size: u32, align: u32) -> u32 {
28            extern crate alloc;
29            use alloc::alloc as a;
30
31            unsafe { a::alloc(a::Layout::from_size_align(size as _, align as _).unwrap()) as _ }
32        }
33
34        #[no_mangle]
35        extern "C" fn __scotch_free(ptr: u32, size: u32, align: u32) {
36            extern crate alloc;
37            use alloc::alloc as a;
38
39            unsafe {
40                a::dealloc(
41                    ptr as _,
42                    a::Layout::from_size_align(size as _, align as _).unwrap(),
43                )
44            }
45        }
46    };
47}