nodo_std 0.18.5

Standard codelets for NODO
Documentation
// Copyright 2023 David Weikersdorfer

use nodo::prelude::*;

/// Publishes one clone of a value each frame (without Message)
pub struct RawCloner<T>(T);

impl<T> RawCloner<T> {
    pub fn new(blueprint: T) -> Self {
        Self(blueprint)
    }
}

impl<T: Clone + Send + Sync> Codelet for RawCloner<T> {
    type Status = DefaultStatus;
    type Config = ();
    type Rx = ();
    type Tx = DoubleBufferTx<T>;
    type Signals = ();

    fn build_bundles(_: &Self::Config) -> (Self::Rx, Self::Tx) {
        ((), DoubleBufferTx::new(1))
    }

    fn step(&mut self, _cx: Context<Self>, _: &mut Self::Rx, tx: &mut Self::Tx) -> Outcome {
        tx.push(self.0.clone())?;
        SUCCESS
    }
}

/// Publishes one message with a clone of a value each frame
pub struct Cloner<T>(T);

impl<T> Cloner<T> {
    pub fn new(blueprint: T) -> Self {
        Self(blueprint)
    }
}

impl<T: Clone + Send + Sync> Codelet for Cloner<T> {
    type Status = DefaultStatus;
    type Config = ();
    type Rx = ();
    type Tx = MessageTx<T>;
    type Signals = ();

    fn build_bundles(_: &Self::Config) -> (Self::Rx, Self::Tx) {
        ((), MessageTx::new(1))
    }

    fn step(&mut self, cx: Context<Self>, _: &mut Self::Rx, tx: &mut Self::Tx) -> Outcome {
        tx.push(cx.clocks.sys_mono.now(), self.0.clone())?;
        SUCCESS
    }
}