hitbox-derive 0.2.0

Derive macros for hitbox caching framework
Documentation

hitbox-derive

Derive macros for the Hitbox caching framework.

This crate provides procedural macros to reduce boilerplate when using hitbox-fn.

Macros

  • #[cached] - Attribute macro that transforms an async function into a cacheable function with a builder-style API for configuring backend, policy, and context.

  • #[derive(KeyExtract)] - Derive the KeyExtract trait for structs to control how they contribute to cache keys. Supports #[key_extract(skip)] and #[key_extract(name = "...")] field attributes.

  • #[derive(CacheableResponse)] - Derive the CacheableResponse trait for return types. Supports #[cacheable_response(skip)] to exclude fields from caching (reconstructed via Default).

  • #[derive(CacheableRequest)] - Derive the CacheableRequest trait with standard cache policy logic.

Usage

This crate is typically used through hitbox-fn with the derive feature enabled:

[dependencies]
hitbox-fn = { version = "0.1", features = ["derive"] }
use hitbox_fn::prelude::*;

#[derive(KeyExtract)]
struct UserId(u64);

#[derive(Clone, Serialize, Deserialize, CacheableResponse)]
struct User {
    id: u64,
    name: String,
    #[cacheable_response(skip)]
    session_token: Option<String>,
}

#[cached]
async fn fetch_user(id: UserId) -> Result<User, Error> {
    // expensive operation
}