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