SCONES: Flexible proc macro for generating constructors and builders

Github repo

Generates constructors and builders for structs (including tuple structs and structs with templates). I wanted to make something that was simple to work with but also easy to make the sorts of tiny changes that feel cumbersome to do manually, such as having two different constructors with only one difference between them. Some examples snipped from the readme:

use scones::{make_builder, make_constructor};

struct Basic {
    int: i32,
    string: String,
let instance = Basic::new(int, string);
let instance = BasicBuilder::new()
// Triggers a compile-time error because we have 
// not specified all fields yet:
// let instance = BasicBuilder::new().build();

#[make_constructor(pub new_identical(shared: i32))]
pub struct MultipleConstructors {
    #[value(shared for new_identical)]
    pub a: i32,
    #[value(shared for new_identical)]
    pub b: i32,
    #[value(shared for new_identical)]
    pub c: i32,

    #[value(false for new)]
    pub identical: bool,
let instance = MultipleConstructors::new(1, 2, 3);
let instance = MultipleConstructors::new_identical(123);

#[make_constructor(pub default_number)]
pub struct TupleStruct(
    #[value(30 for default_number)] i32,
    #[value("Unnamed".to_owned() for TupleStructBuilder)] String,
let instance = TupleStruct::default_number(field_1);
let instance = TupleStructBuilder::new().field_0(12345).build();

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.