#[wasm_split]Expand description
Indicate a function as a split point.
The macro emits a function with the same signature, except that it is async. Calls to this function will first load
the module into which the input function was split into before forwarding the arguments and the result. On non-wasm
targets, the function will be called directly.
The annotated function must fulfill the requirements a typical extern declared function must fufill:
- It can not be
async. If you want to support this, you mustBoxor otherwise wrap theFutureinto adynobject. Also see thereturn_wrapperoption for some further hints. - It can not be
const. - It can not make use of a receiver argument, generics or an
implreturn type. - By default,
"Rust"is assumed as the ABI, but you can change this by declaring the function asextern "ABI".
ยงSyntax
wasm_split($module:ident (, $option ),* ) => { ... };All functions with the same specified $module end up in one split off WASM chunk.
The following options are supported:
-
wasm_split_path = $this:pathchanges the path at which the runtime support crate is expected. As a framework, you might want to reexport this from some hidden module path. Default:::wasm_split_helpers. -
return_wrapper( let $bindings:pat = _ ; $compute:block -> $ret:ty ). A rather low-level option to support rewriting the result of the wrapped function. The generated wrapper will, rather than directly return the result from the user-given function, bind this to$bindingsand emit the statements in$computeto generate the return value of the wrapper with the return type indicated by$ret.Example use case:
return_wrapper( let future = _ ; { future.await } -> Output)toawaita future directly in the wrapper. -
preload( $( #[$attr] )* $preload_name:ident )generates an additional preload function$preload_namewith the signatureasync fn()which can be used to fetch the module in which the wrapped function is contained without calling it.