punch_api is the Punch WebAssembly public API.
It consists of interfaces allowing you to write wasm functions able to run on the Punch as FaaS.
Usage
- Define the input and output types of your function. They have to respectively implement the
serde::Deserializeandserde::Serializetraits. - Define your custom function by impleting the
punch_api::Functiontrait for the type you define. - Register the previous type by calling the
register!macro on it. - You can raise errors by returning a
punch_api::Errorwith an error message.
Et voilĂ ! By compiling your library to wasm, you are able to run your Function on the Punch.
use ;
use ;
;
register!;
punch_api::Function trait
The punch_api::Function is a generic trait taking 3 arguments: a lifetime parameter, an input type and an output type.
The trait defines a method execute that returns a pointer to the result giving the argument input.
You may implement your data logic in this method.
/// The Function trait is the interface for runnable functions on Punch FaaS.
///
/// # Arguments
///
/// * `'a` - lifetime parameter for serde::Deserialize
/// * `InputType` - input type. It implements the trait serde::Deserialize
/// * `OutputType` - output type. It implements the trait serde::Serialize