macro_rules! host_fn {
($pub:vis $name: ident ($($arg:ident : $argty:ty),*) $(-> $ret:ty)? $b:block) => { ... };
($pub:vis $name: ident ($user_data:ident : $dataty:ty; $($arg:ident : $argty:ty),*) $(-> $ret:ty)? $b:block) => { ... };
}Expand description
The host_fn macro is used to define typed host functions
For example, the following defines a host function named add_newline that takes a
string parameter and returns a string result:
extism::host_fn!(add_newline(_user_data: (); a: String) -> String { Ok(a + "\n") });A few things worth noting:
- The function always returns a
Resultthat wraps the specified return type - If a first parameter and type are passed (
_user_dataabove) followed by a semicolon it will be the name of theUserDataparameter and can be used from inside the function