DoLess π¦ β Procedural Macros for Data Mapping and Caching
DoLess is a Rust library offering procedural macros that simplify both
data-to-struct mapping and cache integration patterns.
It provides two main features:
- π§©
#[derive(FromHashMap)]β auto-generates a type-safeFrom<HashMap<String, String>>implementation for simple and nested structs. - β‘
#[cache_it(...)]β injects cache lookup logic directly into your functions.
π Features
π§© Mapping Features
- β
Auto-maps from
HashMap<String, String> - π’ Supports types:
String, numeric primitives,bool,Option<T> - β Supports lists:
Vec<T>,Vec<Option<T>> - πͺ Nested structs with dot notation (
details.name) - β Defaults for missing fields
β‘ Cache Macro Features
- π¦ Add
#[cache_it(...)]to perform cache lookups automatically - π Configurable options:
key = "some:key"key = format!("user:{}", id)var = redisβ custom cache instance namename = cached_dataβ custom binding name
- π Works with any cache backend implementing the
Cachetrait - π Async-aware β supports async functions automatically
π§ Design Intent: Lookup-Only by Default
The #[cache_it] macro performs non-intrusive cache lookups:
let cache_data = cache.;
Thatβs it β no automatic writes.
You decide when to cache the result:
- β Cache only successful responses
- β Skip caching transient or sensitive data
- β Apply your own TTLs or invalidation logic
This intentional design keeps
DoLessflexible and predictable.
Youβre in control of every cache write.
π¦ Installation
[]
= "0.4.1"
Includes:
doless_coreβ Cache trait, shared utilitiesdoless_macrosβ Procedural macrosdolessβ Public re-export crate
β¨ Usage Guide
π§© FromHashMap Example
use FromHashMap;
use HashMap;
β‘ Cache Macro Example
Step 1: Implement the Cache Trait
use Cache;
use ;
use ;
use HashMap;
Step 2: Lookup Function with Optional Write
use cache_it;
use Cache;
Dynamic Key Example
Custom Variable Names
β± Extending Cache: TTL and Custom set_with
In DoLess, the Cache trait supports an overridable method for extra control:
You can override it to implement time-to-live (TTL) or other advanced behaviors.
Example extended cache:
use ;
Now you can call:
cache.set_with; // cache for 2 minutes
π§ͺ Testing
Full examples and integration tests live under:
Run with:
π§ Roadmap
| Feature | Status |
|---|---|
| FromHashMap with nested struct support | β |
| Vec and Vec<Option> handling | β |
| Cache attribute macro | β |
| Async auto-detection | β |
| TTL + extended cache (via set_with) | β (manual) |
| Custom derive hooks | π§ Planned |
| Error diagnostics | π§ Planned |
π¦ Project Structure
| Crate | Purpose |
|---|---|
doless_core |
Core cache trait and foundational types |
doless_macros |
Macro implementations for data mapping and caching |
doless |
Unified public API layer |
DoLess β Write Less, Do More.
π¦ Rust procedural macros that make your data + cache handling simpler, safer, and smarter.