logic-mesh 1.0.0

Control logic engine using event based and reactive blocks written in Rust.
Documentation
// Copyright (c) 2022-2023, Radu Racariu.

use uuid::Uuid;

use crate::base::{
    block::{Block, BlockDesc, BlockProps, BlockState},
    input::InputProps,
};

use libhaystack::val::kind::HaystackKind;

use crate::{blocks::InputImpl, blocks::OutputImpl};

use super::util::execute_impl;

/// Outputs true if value of the inputs are equal.
#[block]
#[derive(BlockProps, Debug)]
#[category = "logic"]
pub struct Equal {
    #[input(name = "in1", kind = "Null")]
    pub input1: InputImpl,
    #[input(name = "in2", kind = "Null")]
    pub input2: InputImpl,
    #[output(kind = "Bool")]
    pub out: OutputImpl,
}

impl Block for Equal {
    async fn execute(&mut self) {
        execute_impl(self, |in1, in2| in1 == in2).await;
    }
}

#[cfg(test)]
mod test {

    use crate::{
        base::block::Block, base::block::test_utils::write_block_inputs, blocks::logic::Equal,
    };

    #[tokio::test]
    async fn test_eq_block() {
        let mut block = Equal::new();

        write_block_inputs([(&mut block.input1, "true"), (&mut block.input2, "true")]).await;

        block.execute().await;
        assert_eq!(block.out.value, true.into());
    }
}