Method Chaining
A Rust procedural macro that automatically makes functions and structs chainable.
Usage
For Functions
The #[chainable] attribute transforms functions to return self, enabling method chaining:
use chainable;
// Now you can chain methods:
let builder = default
.set_name
.set_age;
For Structs
The #[chainable] attribute automatically generates with_* methods for all fields:
// Automatically generates:
// - with_host(self, value: String) -> Self
// - with_port(self, value: u16) -> Self
// - with_timeout(self, value: u64) -> Self
let config = default
.with_host
.with_port
.with_timeout;
Requirements
- Functions must have
&mut selformut selfas the first parameter - Functions should not have explicit return types
- Functions should not contain explicit return statements with values