ncomm_core/node.rs
1//!
2//! A Singular Unit of Work.
3//!
4//! In NComm, Nodes are thought of as an individual unit of work that is
5//! performed every x microseconds. The guiding principle of an NComm
6//! Node is that units of work can be split up into individual microservices
7//! that can execute on their own via data received from various communication
8//! methods and send their outputs to the next process that processes their
9//! information.
10//!
11
12/// A Node represents a singular process that performs some singular
13/// purpose
14///
15/// Nodes should also all be given unique IDs so that they can be identified as
16/// trait objects.
17pub trait Node<ID: PartialEq>: Send {
18 /// Return the node's ID
19 fn get_id(&self) -> ID;
20
21 /// Return the node's update rate (in us)
22 fn get_update_delay_us(&self) -> u128;
23
24 /// Complete the necessary setup functionalities for a Node.
25 ///
26 /// Note: this method is called on Start for the executor or
27 /// (if the executor was not formally started) before the executor
28 /// begins updating nodes.
29 fn start(&mut self) {}
30
31 /// Update is called by the executor every get_update_delay microseconds.
32 ///
33 /// This can be compared to Arduino's `void loop` and should include the
34 /// work completed by this node every "tick".
35 fn update(&mut self) {}
36
37 /// When an executor is stopped or has finished executing nodes, it will call
38 /// this method on all of its nodes so this should clean up any work
39 /// the node needs to do.
40 fn shutdown(&mut self) {}
41}