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

An implementation runs with an array of inputs and returns a value (or null) and a bool indicating if it should be ran again.

Any ‘implementation’ of a function must implement this trait

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 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

The run method is used to execute the implementation

Implementors