//! test a connection from a multiport to another multiport of the same reactor use boomerang::{builder::prelude::*, runtime, Reaction, Reactor}; #[derive(Reactor)] #[reactor( state = "usize", reaction = "ReactionStartup", reaction = "ReactionIn" )] struct Node { input: [TypedPortKey; NUM_NODES], output: [TypedPortKey; NUM_NODES], } #[derive(Reaction)] #[reaction(reactor = "Node", triggers(startup))] struct ReactionStartup<'a, const NUM_NODES: usize> { output: [runtime::OutputRef<'a, i32>; NUM_NODES], } impl Trigger> for ReactionStartup<'_, NUM_NODES> { fn trigger(mut self, _ctx: &mut runtime::Context, _state: &mut usize) { for (i, out) in self.output.iter_mut().enumerate() { **out = Some(i as i32); } } } #[derive(Reaction)] #[reaction(reactor = "Node")] struct ReactionIn<'a, const NUM_NODES: usize> { input: [runtime::InputRef<'a, i32>; NUM_NODES], } impl Trigger> for ReactionIn<'_, NUM_NODES> { fn trigger(self, _ctx: &mut runtime::Context, _state: &mut usize) { let count = self.input.iter().filter(|x| x.is_some()).count(); assert_eq!(count, NUM_NODES); println!("success") } } #[derive(Reactor)] #[reactor(state = "()", connection(from = "nodes.output", to = "nodes.input"))] struct Main { #[reactor(child = "NUM_NODES")] nodes: Node, } #[test] fn action_values() { tracing_subscriber::fmt::init(); let _ = boomerang_util::runner::build_and_test_reactor::>( "connection_to_self_multiport", (), true, false, ) .unwrap(); }