smelter 0.0.2

Custom derive attribute that automatically derives builder methods
Documentation

Build Status Latest Version

About

Smelter is an extremely lightweight rust proc_macro library to derive "Builder" methods for arbitrary rust structs.

Usage

Setup

[dependencies]
smelter = "*"

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 = User::default();
// ...
     u1.with_email_mut("cardboardbox@example.com".to_string())
      .with_alias_mut("Cardboard box".to_string())
      .with_uid_mut(10u64);
      
// ... somewhere else
    let u2 = User::default()
                .with_email("filecabinate@example.com".to_string())
                .with_alias("File Cabinate".to_string())
                .with_uid(10u64);

More Examples

For more examples see the test.rs

Caveats

  • Will not work for enums, unit structs and tuple structs.