Skip to main content

Crate loopctl_derive

Crate loopctl_derive 

Source
Expand description

Procedural-macro companion to loopctl’s Tool trait.

Tool here is a derive macro: apply it to a Deserialize struct describing the tool’s input and it generates the impl loopctl::tool::Tool block — the name, description, JSON-Schema built statically from the struct’s fields, and a call that deserializes the incoming Value into the struct and dispatches to an inherent async fn run handler you supply.

§Attribute Grammar

On the struct (container attributes):

#[tool(
    name = "snake_case_name",       // default: snake_cased struct ident
    description = "one-liner",       // default: struct doc comment
    read_only,                       // override is_read_only() -> true
    concurrency_safe,                // override is_concurrency_safe() -> true
    system_prompt = "extra hint",    // override system_prompt()
    handler = "my_run",              // default: "run"
    allow_extra                      // omit additionalProperties: false
)]

On each field:

#[tool(
    name = "json_key",               // default: Rust field name (or serde's rename)
    description = "field help",      // default: field doc comment
    skip,                            // exclude from schema + required
    default                          // omit from required, keep in properties
)]

#[serde(rename = "…")] and #[serde(rename_all = "…")] are honored for schema naming, mirroring what serde deserializes with; #[tool(name = "…")] takes precedence over both.

Re-exported from the loopctl crate behind its derive feature, so the usual spelling is:

use loopctl::Tool; // brings both the trait and the derive into scope

See the Tool trait docs in loopctl for the attribute grammar.

Derive Macros§

Tool
Derive loopctl::tool::Tool for a struct.