pub trait Router<S: State>:
Send
+ Sync
+ 'static {
// Required method
fn route(
&self,
state: &S,
) -> Pin<Box<dyn Future<Output = Result<RouteResult, JunctureError>> + Send + '_>>;
}Expand description
Router trait for conditional edge routing
Routers examine the current state and determine which node(s) to execute next.
§Examples
ⓘ
use juncture_core::{edge::{Router, RouteResult}, State, error::JunctureError};
use std::pin::Pin;
struct MyState;
impl State for MyState {
type Update = MyStateUpdate;
}
struct MyStateUpdate;
// Simple router using closure blanket impl
let router = |state: &MyState| -> Pin<Box<dyn std::future::Future<Output = Result<RouteResult, JunctureError>> + '_>> {
Box::pin(async move {
Ok(RouteResult::One("target".to_string()))
})
};Required Methods§
Sourcefn route(
&self,
state: &S,
) -> Pin<Box<dyn Future<Output = Result<RouteResult, JunctureError>> + Send + '_>>
fn route( &self, state: &S, ) -> Pin<Box<dyn Future<Output = Result<RouteResult, JunctureError>> + Send + '_>>
Determine the next node(s) to execute based on current state
§Errors
Returns a JunctureError if routing logic fails.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".