The root crate defined a trait that implementations of flow 'functions' must implement in order for them to be invoked by the flowr (or other) runtime.
Also, in the flowimplderive subdirectory a Dervice macro
called FlowImpl
is defined and implemented.
This should be used on the structure that implements the
function, in order that when compiled for the wasm32
target code is inserted to allocate memory (alloc
) and
to serialize and deserialize the data passed across the
native/wasm boundary.
An example implementation using both of these (the trait and the derive macro) is shown:
``` extern crate core; extern crate flowimpl; extern crate flowimpl_derive;
extern crate serde_json;
use flowimpl::implementation::{Implementation, RUNAGAIN, RunAgain}; use flowimplderive::FlowImpl; use serde_json::Value;
pub struct Compare;
/*
A compare operator that takes two numbers (for now) and outputs the comparisons between them
*/
impl Implementation for Compare {
fn run(&self, mut inputs: Vec
let output = json!({
"equal" : left == right,
"lt" : left < right,
"gt" : left > right,
"lte" : left <= right,
"gte" : left >= right,
});
(Some(output), RUN_AGAIN)
}
} ```