pub struct StateGraph<S>where
S: GraphStateTrait,{ /* private fields */ }Expand description
构建中的状态图。
Implementations§
Source§impl<S> StateGraph<S>where
S: GraphStateTrait,
impl<S> StateGraph<S>where
S: GraphStateTrait,
pub fn new() -> Self
Sourcepub fn add_node<N>(self, id: impl Into<String>, node: N) -> Selfwhere
N: GraphNode<S> + 'static,
pub fn add_node<N>(self, id: impl Into<String>, node: N) -> Selfwhere
N: GraphNode<S> + 'static,
添加一个节点。
Sourcepub fn add_edge(self, from: impl Into<String>, to: impl Into<String>) -> Self
pub fn add_edge(self, from: impl Into<String>, to: impl Into<String>) -> Self
添加一条普通有向边 from -> to。
Sourcepub fn add_conditional_edge(
self,
from: impl Into<String>,
router: impl Fn(&S) -> String + Send + Sync + 'static,
routes: HashMap<String, String>,
) -> Self
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。
Sourcepub fn set_entry_point(self, id: impl Into<String>) -> Self
pub fn set_entry_point(self, id: impl Into<String>) -> Self
设置入口节点 id。
Sourcepub fn set_finish_point(self, id: impl Into<String>) -> Self
pub fn set_finish_point(self, id: impl Into<String>) -> Self
设置结束节点 id。
Sourcepub fn compile(self) -> Result<CompiledGraph<S>>
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> 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