logic-mesh 1.0.0

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

//!
//! Defines mock input and output types for testing
//!

use std::pin::Pin;

use uuid::Uuid;

use crate::base::{
    Status,
    input::{BaseInput, Input, InputProps},
    link::BaseLink,
    output::{BaseOutput, Output},
};
use libhaystack::val::{Value, kind::HaystackKind};

pub type InputImpl = BaseInput<String, String>;

impl InputImpl {
    pub fn new(name: &str, kind: HaystackKind, block_id: Uuid) -> Self {
        Self {
            name: name.to_string(),
            kind,
            block_id,
            ..Default::default()
        }
    }
}

impl Input for InputImpl {
    fn receiver(&mut self) -> Pin<Box<dyn Future<Output = Option<Value>> + Send + '_>> {
        Box::pin(async { None })
    }

    fn try_take(&mut self) -> Option<(Value, Status)> {
        None
    }

    fn set_value(&mut self, _value: Value, _status: Status) {}

    fn status(&self) -> Status {
        Status::Ok
    }
}

pub type OutputImpl = BaseOutput<BaseLink<String>>;

impl Default for OutputImpl {
    fn default() -> Self {
        Self::new(HaystackKind::Null, Uuid::default())
    }
}

impl Output for OutputImpl {
    type Writer = <InputImpl as InputProps>::Writer;

    fn add_link(&mut self, _link: BaseLink<Self::Writer>) {
        self.links.push(_link);
    }

    fn set(&mut self, _value: Value) {
        self.value = _value;
    }

    fn emit_status(&mut self, status: Status) {
        self.effective_status = status;
    }
}