StateGraph

Struct StateGraph 

Source
pub struct StateGraph {
    pub schema: StateSchema,
    pub nodes: HashMap<String, Arc<dyn Node>>,
    pub edges: Vec<Edge>,
}
Expand description

Builder for constructing graphs

Fields§

§schema: StateSchema

State schema

§nodes: HashMap<String, Arc<dyn Node>>

Registered nodes

§edges: Vec<Edge>

Registered edges

Implementations§

Source§

impl StateGraph

Source

pub fn new(schema: StateSchema) -> Self

Create a new graph with the given state schema

Source

pub fn with_channels(channels: &[&str]) -> Self

Create with a simple schema (just channel names, all overwrite)

Source

pub fn add_node<N: Node + 'static>(self, node: N) -> Self

Add a node to the graph

Source

pub fn add_node_fn<F, Fut>(self, name: &str, func: F) -> Self
where F: Fn(NodeContext) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<NodeOutput>> + Send + 'static,

Add a function as a node

Source

pub fn add_edge(self, source: &str, target: &str) -> Self

Add a direct edge from source to target

Source

pub fn add_conditional_edges<F, I>( self, source: &str, router: F, targets: I, ) -> Self
where F: Fn(&State) -> String + Send + Sync + 'static, I: IntoIterator<Item = (&'static str, &'static str)>,

Add a conditional edge with a router function

Source

pub fn add_conditional_edges_arc<I>( self, source: &str, router: RouterFn, targets: I, ) -> Self
where I: IntoIterator<Item = (&'static str, &'static str)>,

Add a conditional edge with an Arc router (for pre-built routers)

Source

pub fn compile(self) -> Result<CompiledGraph>

Compile the graph for execution

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.