flowrs_std/nodes/
debug.rs1use std::{any::Any, fmt::Debug, rc::Rc};
2
3use flowrs_derive::Connectable;
4use serde_json::Value;
5
6use flowrs::{
7 connection::{Input, Output, RuntimeConnectable},
8 node::{Node, State, UpdateError, Context},
9};
10
11#[derive(Connectable)]
12pub struct DebugNode<I>
13where
14 I: Clone,
15{
16 name: String,
17 _state: State<Option<I>>,
18 _props: Value,
19 _context: State<Context>,
20
21 #[input]
22 pub input: Input<I>,
23 #[output]
24 pub output: Output<I>,
25}
26
27impl<I> DebugNode<I>
28where
29 I: Clone,
30{
31 pub fn new(name: &str, context: State<Context>, props: Value) -> Self {
32 Self {
33 name: name.into(),
34 _state: State::new(None),
35 _props: props,
36 _context: context.clone(),
37 input: Input::new(),
38 output: Output::new(context.clone()),
39 }
40 }
41}
42
43impl<I> Node for DebugNode<I>
44where
45 I: Clone + Debug + Send + 'static,
46{
47 fn on_init(&self) {}
48
49 fn on_ready(&self) {}
50
51 fn on_shutdown(&self) {}
52
53 fn name(&self) -> &str {
54 &self.name
55 }
56
57 fn update(&self) -> Result<(), UpdateError> {
58 if let Ok(input) = self.input.next_elem() {
59 println!("{:?}", input);
60 self.output.clone().send(input).unwrap();
61 }
62 Ok(())
63 }
64}