Skip to main content

Module node

Module node 

Source
Expand description

Node — the flagship surface of blueprint §9.1.

use astrs_node_api::prelude::*;

fn main() -> Result<(), NodeError> {
    let (mut node, mut events) = Node::init_from_env()?;
    let mut echo = node.raw_output("echo")?;

    while let Some(event) = events.recv() {
        match event {
            Event::Input { id, data, meta } if id == "frames" => {
                echo.send_bytes(data.to_vec(), meta.follow())?;
            }
            Event::Stop(_) => break,
            _ => {}
        }
    }
    Ok(())
}

§Four ways in

ConstructorFor
Node::init_from_envA node the daemon spawned (§24.2’s ASTRS_NODE_CONFIG)
Node::builderA node that wants to override the id, endpoint or token
Node::init_from_node_idA path: dynamic node attaching itself (§8.3)
Node::init_testingA unit test, against an in-process daemon

All four produce the same (Node, EventStream) pair, so a node’s body does not know which one started it — which is exactly what makes Node::init_testing able to exercise the real thing.

§Ownership

Node owns the session; crate::EventStream owns the reading end. Dropping the node closes its outputs and ends the session; dropping the stream tells the daemon to stop queueing (§7.3 EventStreamDropped). Either can be dropped first.

Re-exports§

pub use builder::NodeBuilder;
pub use init::Registration;

Modules§

builder
NodeBuilder — the constructor for everything init_from_env does not cover (blueprint §9.1).
extension
The extension table client (blueprint §9.1’s ext_store/load/drop, §7.3).
init
The registration handshake (blueprint §7.3).
logging
Node logging (blueprint §9.1’s log_{error..trace} / log_with_fields).

Structs§

Node
A live participant in a dataflow.