Skip to main content

ToolsBuilder

Struct ToolsBuilder 

Source
pub struct ToolsBuilder<S = Blank, M = NoMeta>
where S: BuilderState,
{ /* private fields */ }
Expand description

Typestate builder for ToolCollection.

The type parameter S tracks the builder state:

  • Blank — initial. Can call with_context or (in the future) FFI adapter methods.
  • Native — context was set. FFI methods unavailable.
  • Scripted — FFI adapters added. with_context unavailable.

M is the metadata type, defaulting to NoMeta. Change it via with_meta.

§Typestate enforcement

Calling with_context after it has already been called does not compile:

use tools_core::builder::{ToolsBuilder, Native};
use std::sync::Arc;

// ERROR: ToolsBuilder<Native, _> has no method `with_context`
let b = ToolsBuilder::new()
    .with_context(Arc::new(42_u32))
    .with_context(Arc::new(42_u32));

Implementations§

Source§

impl ToolsBuilder

Source

pub fn new() -> ToolsBuilder

Create a new builder in the Blank state with NoMeta. Use with_meta to change the metadata type.

Source§

impl<M> ToolsBuilder<Blank, M>

Source

pub fn with_context<T>(self, ctx: Arc<T>) -> ToolsBuilder<Native, M>
where T: Send + Sync + 'static,

Set a shared context that will be injected into every tool whose first parameter is named ctx. Transitions to the Native state, locking out FFI adapter methods.

Source§

impl<S, M> ToolsBuilder<S, M>
where S: BuilderState,

Source

pub fn with_meta<M2>(self) -> ToolsBuilder<S, M2>

Change the metadata type. This is a phantom-only transition — no data is stored. M2 is used at [collect] time to deserialize each tool’s #[tool(...)] attributes.

Source§

impl<M> ToolsBuilder<Blank, M>

Source

pub fn collect(self) -> Result<ToolCollection<M>, ToolError>

Build the collection from the global tool inventory (no context). Tools that require context will produce a ToolError::MissingCtx error.

Source§

impl<M> ToolsBuilder<Native, M>

Source

pub fn collect(self) -> Result<ToolCollection<M>, ToolError>

Build the collection from the global tool inventory, injecting the stored context into tools that require it. Validates that every context-requiring tool expects the same type.

Source§

impl<M> ToolsBuilder<Scripted, M>

Source

pub fn collect(self) -> Result<ToolCollection<M>, ToolError>

Build the collection from the global tool inventory (no context). In the future, this will also load scripts from configured FFI adapter paths.

Trait Implementations§

Source§

impl Default for ToolsBuilder

Source§

fn default() -> ToolsBuilder

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

Auto Trait Implementations§

§

impl<S, M> Freeze for ToolsBuilder<S, M>

§

impl<S = Blank, M = NoMeta> !RefUnwindSafe for ToolsBuilder<S, M>

§

impl<S, M> Send for ToolsBuilder<S, M>

§

impl<S, M> Sync for ToolsBuilder<S, M>

§

impl<S, M> Unpin for ToolsBuilder<S, M>

§

impl<S, M> UnsafeUnpin for ToolsBuilder<S, M>

§

impl<S = Blank, M = NoMeta> !UnwindSafe for ToolsBuilder<S, M>

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<M> MetaArg<M> for M

Source§

fn into_meta(self) -> M

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.