Skip to main content

EngineBuilder

Struct EngineBuilder 

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

Source

pub fn new() -> Self

Creates a new builder with default settings.

A thinker must be provided via thinker before calling build.

Source§

impl<Ctx, Out> EngineBuilder<Ctx, Out>
where Ctx: Send + Sync, Out: Send + Sync,

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<Ctx, Out> Default for EngineBuilder<Ctx, Out>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<Ctx, Out> !RefUnwindSafe for EngineBuilder<Ctx, Out>

§

impl<Ctx, Out> !UnwindSafe for EngineBuilder<Ctx, Out>

§

impl<Ctx, Out> Freeze for EngineBuilder<Ctx, Out>

§

impl<Ctx, Out> Send for EngineBuilder<Ctx, Out>

§

impl<Ctx, Out> Sync for EngineBuilder<Ctx, Out>

§

impl<Ctx, Out> Unpin for EngineBuilder<Ctx, Out>

§

impl<Ctx, Out> UnsafeUnpin for EngineBuilder<Ctx, Out>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.