# 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:
```rust
use method_chaining::chainable;
struct Builder {
name: String,
age: u32,
}
impl Builder {
#[chainable]
fn set_name(&mut self, name: String) {
self.name = name;
// No need to return self - it's added automatically
}
#[chainable]
fn set_age(&mut self, age: u32) {
self.age = age;
}
}
// Now you can chain methods:
let builder = Builder::default()
.set_name("Alice".to_string())
.set_age(30);
```
### For Structs
The `#[chainable]` attribute automatically generates `with_*` methods for all fields:
```rust
#[chainable]
struct Config {
host: String,
port: u16,
timeout: u64,
}
// Automatically generates:
// - with_host(self, value: String) -> Self
// - with_port(self, value: u16) -> Self
// - with_timeout(self, value: u64) -> Self
let config = Config::default()
.with_host("localhost".to_string())
.with_port(8080)
.with_timeout(5000);
```
## Requirements
- Functions must have `&mut self` or `mut self` as the first parameter
- Functions should not have explicit return types
- Functions should not contain explicit return statements with values