cachelito-macro-utils

Crates.iocachelito-macro-utils
lib.rscachelito-macro-utils
version0.16.0
created_at2025-11-10 15:33:05.754694+00
updated_at2026-01-08 20:08:22.646903+00
descriptionShared utilities for cachelito procedural macros
homepagehttps://github.com/josepdcs/cachelito
repositoryhttps://github.com/josepdcs/cachelito
max_upload_size
id1925711
size57,716
Josep DamiĆ  Carbonell SeguĆ­ (josepdcs)

documentation

https://docs.rs/cachelito-macro-utils

README

cachelito-macro-utils

Shared utilities for cachelito procedural macros.

This crate provides common parsing and code generation utilities used by both cachelito-macros (sync) and cachelito-async-macros (async).

Purpose

This crate eliminates code duplication between the sync and async macro implementations by providing shared functionality for:

  • Parsing macro attributes (limit, policy, ttl, name, scope)
  • Generating cache key expressions
  • Common data structures

Usage

This crate is not meant to be used directly. It's an internal dependency of:

  • cachelito-macros - Procedural macros for sync functions
  • cachelito-async-macros - Procedural macros for async functions

Public API

Parsing Functions

  • parse_limit_attribute() - Parse the limit attribute (returns Some(usize) or None)
  • parse_policy_attribute() - Parse the policy attribute (returns string: "fifo" or "lru")
  • parse_ttl_attribute() - Parse the ttl attribute (returns Some(u64) or None)
  • parse_name_attribute() - Parse the name attribute (returns Option<String>)
  • parse_scope_attribute() - Parse the scope attribute (returns string: "thread" or "global")

Code Generation

  • generate_key_expr() - Generate cache key expression using Debug formatting

Data Structures

  • SyncCacheAttributes - Struct holding parsed macro attributes with defaults for sync macros
  • AsyncCacheAttributes - Struct holding parsed macro attributes with defaults for async macros

Example

use cachelito_macro_utils::{parse_limit_attribute, parse_policy_attribute};

// In a procedural macro
for nv in parsed_args {
    if nv.path.is_ident("limit") {
        attrs.limit = parse_limit_attribute(&nv);
    } else if nv.path.is_ident("policy") {
        attrs.policy = parse_policy_attribute(&nv);
    }
}

License

Licensed under Apache-2.0.

Commit count: 49

cargo fmt