claude-api-derive 0.5.0

Procedural macros for claude-api (Tool derive)
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 12.09 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 296.84 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 31s Average build duration of successful builds.
  • all releases: 31s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • joshrotenberg

Procedural macros for claude-api.

Re-exported from the parent crate behind the derive feature; users should write claude_api::derive::Tool, not depend on this crate directly.

#[derive(Tool)]

Derive an implementation of claude_api::tool_dispatch::Tool for a struct that already implements serde::Deserialize and schemars::JsonSchema. The struct's fields define the tool input; the user supplies the behavior via an inherent async fn run(self).

use claude_api::derive::Tool;
use claude_api::tool_dispatch::ToolError;
use serde::Deserialize;
use schemars::JsonSchema;

/// Get the current weather for a city.
#[derive(Deserialize, JsonSchema, Tool)]
struct GetWeather {
    /// City to look up.
    city: String,
}

impl GetWeather {
    async fn run(self) -> Result<serde_json::Value, ToolError> {
        Ok(serde_json::json!({"temp": 72, "city": self.city}))
    }
}

// Use:
let tool = GetWeather::tool();

Attribute syntax

  • #[tool(name = "...")] -- override the tool name. Default: snake_case of the type name.
  • #[tool(description = "...")] -- override the description. Default: the first line of the struct's doc comment.