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.

// ERROR: with_language not available after with_context
let b = ToolsBuilder::new()
    .with_context(Arc::new(42_u32))
    .with_language(tools_core::Language::Python);
Source

pub fn with_language(self, lang: Language) -> ToolsBuilder<Scripted, M>

Set the scripting language for FFI tool loading. Transitions to the Scripted state, locking out with_context.

Use from_path to add script directories after calling this.

// ERROR: with_context not available after with_language
let b = ToolsBuilder::new()
    .with_language(tools_core::Language::Python)
    .with_context(Arc::new(42_u32));
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 from_path(self, path: impl Into<PathBuf>) -> ToolsBuilder<Scripted, M>

Add a script path to load tools from. Can be called multiple times to load from several paths.

Source§

impl<M> ToolsBuilder<Scripted, M>

Source

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

Build the collection. Collects #[tool] inventory tools (no context), then loads scripted tools from configured paths via the selected language adapter.

No paths configured = inventory tools only.

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.