pub trait Node<S: State>: Send + Sync {
// Required method
fn invoke<'life0, 'life1, 'async_trait>(
&'life0 self,
state: S,
config: &'life1 Config,
) -> Pin<Box<dyn Future<Output = Result<S>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
The core trait for graph nodes.
A node is a unit of computation that takes state and produces updated state. Nodes can be async functions, closures, or custom types implementing this trait.
§Example
use rust_langgraph::{Node, Config, Error};
use async_trait::async_trait;
#[derive(Clone)]
struct MyState {
count: i32,
}
struct IncrementNode;
#[async_trait]
impl Node<MyState> for IncrementNode {
async fn invoke(&self, mut state: MyState, _config: &Config) -> Result<MyState, Error> {
state.count += 1;
Ok(state)
}
}