rumbok
rumbok is a Lombok-inspired derive macro library for Rust.
It provides Getter, Setter, and Data derive macros to reduce boilerplate code,
while keeping Rust's ownership and borrowing semantics explicit and safe.
โจ Features
#[derive(Setter)]- Generates
set_xxx(&mut self, value: T)methods
- Generates
#[derive(Getter)]- Generates
get_xxx(&self) -> &T/&strmethods
- Generates
#[derive(Data)]- Generates both Getter and Setter
- Supports generics, lifetimes, and
whereclauses - Correctly handles owned types and reference types
- UI tests using
trybuild(including compile-fail cases)
๐ฆ Installation
[]
= "0.1"
๐ Basic Usage
Data (Getter + Setter)
use Data;
๐งฉ Individual Derives
Setter
use Setter;
Getter
use Getter;
Getter rules:
| Field Type | Return Type |
|---|---|
T |
&T |
&T |
&T |
&mut T |
&T |
๐ง Design Philosophy
- Do not hide Rust's ownership and borrowing rules
- Prefer explicit and predictable APIs
- Avoid guessing trait implementations such as
Copy
Getters always return references by design.
โ ๏ธ Limitations
- Tuple structs and unit structs are not supported
- Field-level attributes are not yet implemented
- Enum types are not supported
- No automatic
Copydetection
๐งช Testing
This crate uses:
- Unit tests for macro expansion
- UI tests with
trybuild
๐ Debugging Macros
To inspect expanded macros, use cargo-expand:
๐ License
Licensed under either of:
- MIT License
๐ Motivation
Inspired by Java's Lombok, this project aims to:
- Reduce boilerplate
- Preserve Rust's safety guarantees
- Provide simple and predictable derive macros
๐ง Roadmap
#[getter(skip)],#[setter(skip)]#[getter(by_value)]- Option-aware getters
#[derive(Value)]#[derive(Constructor)]
Enjoy writing less boilerplate with rumbok โจ