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 callwith_contextor (in the future) FFI adapter methods.Native— context was set. FFI methods unavailable.Scripted— FFI adapters added.with_contextunavailable.
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
impl ToolsBuilder
Source§impl<M> ToolsBuilder<Blank, M>
impl<M> ToolsBuilder<Blank, M>
Sourcepub fn with_context<T>(self, ctx: Arc<T>) -> ToolsBuilder<Native, M>
pub fn with_context<T>(self, ctx: Arc<T>) -> ToolsBuilder<Native, M>
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,
impl<S, M> ToolsBuilder<S, M>where
S: BuilderState,
Sourcepub fn with_meta<M2>(self) -> ToolsBuilder<S, M2>
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>where
M: DeserializeOwned,
impl<M> ToolsBuilder<Blank, M>where
M: DeserializeOwned,
Sourcepub fn collect(self) -> Result<ToolCollection<M>, ToolError>
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>where
M: DeserializeOwned,
impl<M> ToolsBuilder<Native, M>where
M: DeserializeOwned,
Sourcepub fn collect(self) -> Result<ToolCollection<M>, ToolError>
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>where
M: DeserializeOwned,
impl<M> ToolsBuilder<Scripted, M>where
M: DeserializeOwned,
Sourcepub fn collect(self) -> Result<ToolCollection<M>, ToolError>
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.