About
Smelter is an extremely lightweight rust proc_macro library to derive "Builder" methods for arbitrary rust structs.
Usage
Setup
[]
= "*"
Add the following to the file in which you with to use smelter.
#![feature(proc_macro, custom_attribute)]
#[macro_use]
extern crate smelter;
Then just add #[derive(Builder)]
above your struct,
Example
#![feature(proc_macro, custom_attribute)]
#[macro_use] extern crate smelter;
#[derive(PartialEq, Builder, Default, Debug, Clone)] #[smelter(prefix="with_")] pub struct User { pub uid: u64, pub email: String, pub alias: String, pub friends: Vec, }
Invocation
// ... somewhere in your code
let mut u1 = default;
// ...
u1.with_email_mut
.with_alias_mut
.with_uid_mut;
// ... somewhere else
let u2 = default
.with_email
.with_alias
.with_uid;
More Examples
For more examples see the test.rs
Caveats
- Will not work for enums, unit structs and tuple structs.