Skip to main content

StateGraph

Struct StateGraph 

Source
pub struct StateGraph<S>
where S: GraphStateTrait,
{ /* private fields */ }
Expand description

构建中的状态图。

Implementations§

Source§

impl<S> StateGraph<S>
where S: GraphStateTrait,

Source

pub fn new() -> Self

Source

pub fn add_node<N>(self, id: impl Into<String>, node: N) -> Self
where N: GraphNode<S> + 'static,

添加一个节点。

Source

pub fn add_edge(self, from: impl Into<String>, to: impl Into<String>) -> Self

添加一条普通有向边 from -> to

Source

pub fn add_conditional_edge( self, from: impl Into<String>, router: impl Fn(&S) -> String + Send + Sync + 'static, routes: HashMap<String, String>, ) -> Self

添加一条条件边:

  • router 根据当前状态返回一个路由 key;
  • routes 将 key 映射到下一跳节点 id。
Source

pub fn set_entry_point(self, id: impl Into<String>) -> Self

设置入口节点 id。

Source

pub fn set_finish_point(self, id: impl Into<String>) -> Self

设置结束节点 id。

Source

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

编译为只读的 CompiledGraph,用于实际运行。

在编译阶段会做若干完整性检查:

  • 入口节点必须存在;
  • 如果设置了结束节点,则结束节点也必须存在;
  • 所有边的起点/终点都必须在节点集合中出现。

Auto Trait Implementations§

§

impl<S> Freeze for StateGraph<S>

§

impl<S> !RefUnwindSafe for StateGraph<S>

§

impl<S> Send for StateGraph<S>

§

impl<S> Sync for StateGraph<S>

§

impl<S> Unpin for StateGraph<S>

§

impl<S> UnsafeUnpin for StateGraph<S>

§

impl<S> !UnwindSafe for StateGraph<S>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.