Skip to main content

raio/
lib.rs

1//! raio is a deterministic realtime runtime for apps made of nodes in separate processes.
2//!
3//! A node's tasks set values on output ports, and wait for values on input ports and for logical
4//! time to pass. Every value has a timestamp, a point in logical time, and a node moves to a
5//! timestamp only once none of its inputs can still bring an earlier value. So every run of an
6//! app sees the same events in the same order, however fast each process happens to be. What
7//! comes from outside the app, such as an [`app::Action`] or the future of another runtime, gets
8//! its timestamp from the wall clock and is marked physical.
9//!
10//! ```no_run
11//! use raio::app::{App, Builder, InputPort, Node, OutputPort, Ports, node};
12//! use raio::time::MS;
13//!
14//! #[derive(Ports)]
15//! struct Producer {
16//!     node: Node,
17//!     out: OutputPort<String>,
18//! }
19//!
20//! #[node]
21//! impl Producer {
22//!     fn new(builder: &mut Builder) -> Self {
23//!         Self {
24//!             node: builder.node(),
25//!             out: builder.output(),
26//!         }
27//!     }
28//!
29//!     #[task]
30//!     async fn produce(&self) {
31//!         self.node.wait(1 * MS).await;
32//!         self.out.set("hello world".to_string());
33//!     }
34//! }
35//!
36//! #[derive(Ports)]
37//! struct Sink {
38//!     input: InputPort<String>,
39//! }
40//!
41//! #[node]
42//! impl Sink {
43//!     fn new(builder: &mut Builder) -> Self {
44//!         Self {
45//!             input: builder.input(),
46//!         }
47//!     }
48//!
49//!     #[reaction(input)]
50//!     fn show(&self) {
51//!         println!("sink received {:?}", *self.input.get().unwrap());
52//!     }
53//! }
54//!
55//! let mut app = App::new();
56//! let producer = app.create_node(Producer::new);
57//! let sink = app.create_node(Sink::new);
58//! app.connect(&producer.out, &sink.input);
59//! app.run();
60//! ```
61//!
62//! # Modules
63//!
64//! - [`app`]: the building blocks of a node program, and the `App` that connects and launches
65//!   nodes.
66//! - [`time`]: timestamps and durations.
67//! - [`serializer`] and [`transport`]: how a connection encodes values and carries them.
68//! - [`node`]: the scheduler that orders the events of one node by timestamp.
69//! - [`coordinator`] and [`messages`]: the graph of an app, and how its nodes are wired and shut
70//!   down together.
71//! - [`diagram`]: a picture of an app, with its nodes, their tasks, and their connections.
72//! - [`runtime`] and [`driver`]: the single-threaded executor under each node, and its I/O and
73//!   timers.
74//!
75//! # Features
76//!
77//! - `serde_bytes`: encodes the value of a frame as one block of bytes, not byte by byte, which
78//!   is much faster for large values. The Python binding has it on. A node built with it and a
79//!   node built without it can connect.
80
81// The code that `#[derive(Ports)]` writes names this crate, in this crate too.
82extern crate self as raio;
83
84pub mod app;
85pub mod coordinator;
86pub mod diagram;
87pub mod driver;
88pub mod messages;
89pub mod node;
90pub mod runtime;
91pub mod serializer;
92pub mod time;
93pub mod transport;
94
95/// The version of raio, with the commit hash when built from a git checkout: `0.2.0+abc1234`.
96pub const VERSION: &str = const_format::concatcp!(
97    env!("CARGO_PKG_VERSION"),
98    git_version::git_version!(
99        args = ["--always", "--exclude=*", "--abbrev=7", "--dirty=.dirty"],
100        prefix = "+",
101        fallback = ""
102    )
103);