pub trait Implementation: Sync + Send {
    // Required method
    fn run(&self, inputs: &[Value]) -> Result<(Option<Value>, RunAgain)>;
}
Expand description

A function’s implementation must implement this trait with a single run() method that takes as input an array of values and it returns a Result tuple with an Optional output Value plus a RunAgain indicating if it should be run again. i.e. it has not “completed”, in which case it should not be called again.

Examples

Here is an example implementation of this trait:

use flowcore::{Implementation, RUN_AGAIN, RunAgain};
use flowcore::errors::Result;
use serde_json::Value;
use serde_json::json;

#[derive(Debug)]
pub struct Compare;

/*
    A compare implementation that takes two numbers and outputs the comparisons between them
*/
impl Implementation for Compare {
    fn run(&self, mut inputs: &[Value]) -> Result<(Option<Value>, RunAgain)> {
        let left = inputs[0].as_i64().unwrap();
        let right = inputs[1].as_i64().unwrap();

        let output = json!({
                    "equal" : left == right,
                    "lt" : left < right,
                    "gt" : left > right,
                    "lte" : left <= right,
                    "gte" : left >= right
                });

        Ok((None, RUN_AGAIN))
    }
}

Note: It is recommended to implement this trait by using the flow_function macro from the flowmacro crate to simplify input gathering and to hide the boiler plate code around the function implementing the logic.

Required Methods§

source

fn run(&self, inputs: &[Value]) -> Result<(Option<Value>, RunAgain)>

The run method is used to execute the function’s implementation

Implementors§