Skip to main content

Router

Trait Router 

Source
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§

Source

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".

Implementors§

Source§

impl<S, F> Router<S> for F
where S: State, F: Fn(&S) -> &str + Send + Sync + 'static,

Blanket implementation for sync functions returning &str

§Examples

use juncture_core::{edge::{Router, RouteResult}, State, error::JunctureError};

struct MyState;
impl State for MyState {
    type Update = MyStateUpdate;
}

struct MyStateUpdate;

// Simple closure router
let router = |state: &MyState| -> &str {
    "target"
};