pub struct BinaryOperatorAggregate<T, F>{ /* private fields */ }Expand description
A channel that reduces values using a binary operator.
This channel maintains a single value and applies a reduction function when new values are written. This is useful for operations like summing, finding max/min, or any other associative binary operation.
§Example
use rust_langgraph::channels::{BaseChannel, BinaryOperatorAggregate};
// Sum reducer
let mut channel = BinaryOperatorAggregate::new(0, |a, b| a + b);
channel.update(vec![serde_json::json!(1), serde_json::json!(2), serde_json::json!(3)]).unwrap();
assert_eq!(channel.get().unwrap(), Some(serde_json::json!(6)));Implementations§
Trait Implementations§
Source§impl<T, F> BaseChannel for BinaryOperatorAggregate<T, F>
impl<T, F> BaseChannel for BinaryOperatorAggregate<T, F>
Source§fn update(&mut self, values: Vec<Value>) -> Result<()>
fn update(&mut self, values: Vec<Value>) -> Result<()>
Update the channel with new values Read more
Source§fn checkpoint(&self) -> Result<Value>
fn checkpoint(&self) -> Result<Value>
Serialize the channel state for checkpointing
Source§fn from_checkpoint(_data: Value) -> Result<Box<dyn BaseChannel>>
fn from_checkpoint(_data: Value) -> Result<Box<dyn BaseChannel>>
Restore the channel state from a checkpoint
Auto Trait Implementations§
impl<T, F> Freeze for BinaryOperatorAggregate<T, F>where
T: Freeze,
impl<T, F> RefUnwindSafe for BinaryOperatorAggregate<T, F>where
T: RefUnwindSafe,
F: RefUnwindSafe,
impl<T, F> Send for BinaryOperatorAggregate<T, F>where
T: Send,
impl<T, F> Sync for BinaryOperatorAggregate<T, F>where
T: Sync,
impl<T, F> Unpin for BinaryOperatorAggregate<T, F>where
T: Unpin,
impl<T, F> UnsafeUnpin for BinaryOperatorAggregate<T, F>where
T: UnsafeUnpin,
impl<T, F> UnwindSafe for BinaryOperatorAggregate<T, F>where
T: UnwindSafe,
F: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more