pub trait IntoNode<S>where
S: State,{
// Required method
fn into_node(self, name: &str) -> Arc<dyn Node<S>> ⓘ;
}Expand description
Conversion trait for creating nodes from async functions
This trait allows async functions with various signatures to be used as nodes in a Juncture graph.
§Supported Function Signatures
The trait supports multiple function signatures for flexibility:
§Forms A-D (existing, without Runtime)
ⓘ
use juncture_core::{IntoNode, State, Node, Command};
use juncture_core::node::NodeFnUpdate;
use std::sync::Arc;
// Form A: fn(S) -> Result<S::Update>
async fn simple_node(state: MyState) -> Result<MyStateUpdate, juncture_core::JunctureError> {
Ok(MyStateUpdate)
}
// Form B: fn(S, RunnableConfig) -> Result<S::Update>
async fn with_config(state: MyState, config: RunnableConfig) -> Result<MyStateUpdate, juncture_core::JunctureError> {
Ok(MyStateUpdate)
}
// Form C: fn(S) -> Result<Command<S>>
async fn with_command(state: MyState) -> Result<Command<MyState>, juncture_core::JunctureError> {
Ok(Command::end())
}
// Form D: fn(S, RunnableConfig) -> Result<Command<S>>
async fn full_form(state: MyState, config: RunnableConfig) -> Result<Command<MyState>, juncture_core::JunctureError> {
Ok(Command::end())
}§Forms E-F (new, with Runtime for dependency injection)
ⓘ
use juncture_core::{IntoNode, State, Runtime};
use juncture_core::node::NodeFnUpdateWithRuntime;
// Form E: fn(S, Runtime<C>) -> Result<S::Update>
async fn with_runtime(state: MyState, runtime: Runtime<MyContext>) -> Result<MyStateUpdate, juncture_core::JunctureError> {
// Access runtime context
let user_id = &runtime.context.user_id;
Ok(MyStateUpdate)
}
// Form F: fn(S, RunnableConfig, Runtime<C>) -> Result<S::Update>
async fn with_all(state: MyState, config: RunnableConfig, runtime: Runtime<MyContext>) -> Result<MyStateUpdate, juncture_core::JunctureError> {
// Full access to state, config, and runtime
Ok(MyStateUpdate)
}§Examples
ⓘ
use juncture_core::{IntoNode, State, Runtime};
use juncture_core::node::NodeFnUpdateWithRuntime;
use std::sync::Arc;
// Create a Runtime with custom context
let runtime = Runtime::with_context(MyContext { user_id: "user-123".to_string() });
// Wrap a Runtime-aware function
let wrapper = NodeFnUpdateWithRuntime::new(
async fn my_node(state: MyState, runtime: Runtime<MyContext>) -> Result<MyStateUpdate, JunctureError> {
// Use runtime context
Ok(MyStateUpdate)
},
runtime
);
// Convert to a node
let node: Arc<dyn Node<MyState>> = wrapper.into_node("my_node");Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".