pub trait State:
Clone
+ Send
+ Sync
+ Serialize
+ for<'de> Deserialize<'de>
+ Debug
+ 'static {
// Required method
fn merge(&mut self, other: Self) -> Result<()>;
// Provided methods
fn to_value(&self) -> Result<Value> { ... }
fn from_value(value: Value) -> Result<Self> { ... }
}Expand description
The core trait for graph state.
Implementors of this trait define how state is merged when multiple nodes produce updates that need to be combined.
§Example
use rust_langgraph::{State, Error};
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
struct CounterState {
count: i32,
}
impl State for CounterState {
fn merge(&mut self, other: Self) -> Result<(), Error> {
self.count += other.count;
Ok(())
}
}Required Methods§
Provided Methods§
Sourcefn from_value(value: Value) -> Result<Self>
fn from_value(value: Value) -> Result<Self>
Create state from JSON value (default implementation)
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".