pub trait Node<Input, Output, Error, Context> {
// Required method
fn run(
&mut self,
input: Input,
context: &mut Context,
) -> impl Future<Output = Result<Output, Error>> + Send;
// Provided method
fn describe(&self) -> Description
where Self: Sized { ... }
}Expand description
The Node trait serves as the core building block.
It defines how Input is processed into an Output (and Error) with a given Context.
§Type Parameters
Input: The type of data consumed by the node.Output: The type of data produced by the node.Error: The type representing possible errors.Context: The type of context used during execution (it should always be a generic).
§Examples
impl<Context: Send> Node<i32, NodeOutput<String>, MyError, Context> for ExampleNode {
async fn run(
&mut self,
input: i32,
_context: &mut Context,
) -> Result<NodeOutput<String>, MyError> {
Ok(NodeOutput::Ok(format!("Processed: {}", input)))
}
fn describe(&self) -> Description {
Description::new_node::<Self, i32, String, MyError, Context>(self)
.with_description("My example node")
}
}Required Methods§
Sourcefn run(
&mut self,
input: Input,
context: &mut Context,
) -> impl Future<Output = Result<Output, Error>> + Send
fn run( &mut self, input: Input, context: &mut Context, ) -> impl Future<Output = Result<Output, Error>> + Send
Runs the node.
This method performs the node’s main computation or transformation logic.
§Parameters
input: The input data to process.context: Mutable reference to a context, which may be used for configuration, logging, or shared state.
§Returns
A Future that resolves to a Result<Output, Error>.
§Examples
impl<Context: Send> Node<i32, String, MyError, Context> for ExampleNode {
async fn run(
&mut self,
input: i32,
_context: &mut Context,
) -> Result<String, MyError> {
Ok(format!("Processed: {}", input))
}
}Provided Methods§
Sourcefn describe(&self) -> Descriptionwhere
Self: Sized,
fn describe(&self) -> Descriptionwhere
Self: Sized,
Describes this node, its type signature and other specifics.
See Description for more details.
§Examples
impl<Context: Send> Node<i32, NodeOutput<String>, MyError, Context> for ExampleNode {
async fn run(&mut self, input: i32, _context: &mut Context)
-> Result<NodeOutput<String>, MyError> { todo!() }
fn describe(&self) -> Description {
Description::new_node::<Self, i32, String, MyError, Context>(self)
.with_description("My example node")
}
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.