use crate::{StdioConfig, StdioError, StdioSystem, System};
use protoflow_core::{Block, BlockResult, BlockRuntime, InputPort, Message};
use protoflow_derive::Block;
use simple_mermaid::mermaid;
#[doc = mermaid!("../../doc/core/drop.mmd")]
#[doc = mermaid!("../../doc/core/drop.seq.mmd" framed)]
#[derive(Block, Clone)]
pub struct Drop<T: Message> {
#[input]
pub input: InputPort<T>,
}
impl<T: Message> Drop<T> {
pub fn new(input: InputPort<T>) -> Self {
Self { input }
}
}
impl<T: Message> Block for Drop<T> {
fn execute(&mut self, _runtime: &dyn BlockRuntime) -> BlockResult {
while let Some(message) = self.input.recv()? {
drop(message);
}
Ok(())
}
}
#[cfg(feature = "std")]
impl<T: Message> StdioSystem for Drop<T> {
fn build_system(_config: StdioConfig) -> Result<System, StdioError> {
use crate::{CoreBlocks, SysBlocks, SystemBuilding};
Ok(System::build(|s| {
let stdin = s.read_stdin();
let dropper = s.drop();
s.connect(&stdin.output, &dropper.input);
}))
}
}
#[cfg(test)]
mod tests {
use super::Drop;
use crate::{System, SystemBuilding};
#[test]
fn instantiate_block() {
let _ = System::build(|s| {
let _ = s.block(Drop::<i32>::new(s.input()));
});
}
}