pub struct EngineBuilder<Ctx, Out> { /* private fields */ }Expand description
Fluent builder for constructing a CoreEngine.
§Example
use xz_agent_core::engine::{CoreEngine, EngineBuilder};
use xz_agent_core::traits::thinker::Thinker;
use xz_agent_core::error::EngineError;
struct MyThinker;
impl Thinker for MyThinker {
type Context = String;
type Output = String;
async fn think(&self, ctx: &Self::Context) -> Result<Self::Output, EngineError> {
Ok(format!("processed: {}", ctx))
}
}
let engine: CoreEngine<String, String> = EngineBuilder::new()
.thinker(MyThinker)
.build()
.unwrap();Implementations§
Source§impl<Ctx, Out> EngineBuilder<Ctx, Out>
impl<Ctx, Out> EngineBuilder<Ctx, Out>
Source§impl<Ctx, Out> EngineBuilder<Ctx, Out>
impl<Ctx, Out> EngineBuilder<Ctx, Out>
Sourcepub fn thinker(
self,
thinker: impl Thinker<Context = Ctx, Output = Out> + 'static,
) -> Self
pub fn thinker( self, thinker: impl Thinker<Context = Ctx, Output = Out> + 'static, ) -> Self
Sets the thinker used to produce output from context.
The thinker is the only required component. All other chains are optional.
Sourcepub fn context(
self,
builder: impl ContextBuilder<Context = Ctx> + 'static,
) -> Self
pub fn context( self, builder: impl ContextBuilder<Context = Ctx> + 'static, ) -> Self
Appends a context builder to the builder chain.
Builders are applied in the order they are added. Each builder receives the context produced by the previous one and may modify it.
Sourcepub fn processor(
self,
processor: impl OutputProcessor<Context = Ctx, Output = Out> + 'static,
) -> Self
pub fn processor( self, processor: impl OutputProcessor<Context = Ctx, Output = Out> + 'static, ) -> Self
Appends an output processor to the processor chain.
Processors are consulted in the order they are added. The first
processor to return Signal::Stop terminates the loop.
Sourcepub fn cancel(self, token: CancellationToken) -> Self
pub fn cancel(self, token: CancellationToken) -> Self
Sets the cancellation token for the engine.
When the token is cancelled, the engine loop exits at the start
of the next turn with EngineError::Cancelled.
Sourcepub fn build(self) -> Result<CoreEngine<Ctx, Out>, EngineError>
pub fn build(self) -> Result<CoreEngine<Ctx, Out>, EngineError>
Builds the CoreEngine.
§Errors
Returns EngineError::Config if no thinker has been set. The
thinker is the only required component; all other chains are optional.