hdk/map_extern.rs
1pub use hdi::map_extern::*;
2
3/// Hides away the gross bit where we hook up integer pointers to length-prefixed guest memory
4/// to serialization and deserialization, and returning things to the host, and memory allocation
5/// and deallocation.
6///
7/// A lot of that is handled by the holochain_wasmer crates but this handles the boilerplate of
8/// writing an extern function as they have awkward input and output signatures:
9///
10/// - requires remembering `#[no_mangle]`
11/// - requires remembering pub extern "C"
12/// - requires juggling GuestPtr on the input and output with the memory/serialization
13/// - doesn't support Result returns at all, so breaks things as simple as `?`
14///
15/// This can be used directly as `map_extern!(external_facing_fn_name, internal_fn_name)` but it is
16/// more idiomatic to use the `#[hdk_extern]` attribute
17///
18/// ```ignore
19/// #[hdk_extern]
20/// pub fn foo(foo_input: FooInput) -> ExternResult<FooOutput> {
21/// // ... do stuff to respond to incoming calls from the host to "foo"
22/// }
23/// ```
24#[macro_export]
25macro_rules! map_extern {
26 ( $name:tt, $f:ident, $input:ty, $output:ty ) => {
27 $crate::prelude::hdi::map_extern!($name, $f, $input, $output);
28 };
29}
30
31#[macro_export]
32macro_rules! map_extern_infallible {
33 ( $name:tt, $f:ident, $input:ty, $output:ty ) => {
34 $crate::prelude::hdi::map_extern_infallible!($name, $f, $input, $output);
35 };
36}