Crates.io | scones |
lib.rs | scones |
version | 0.1.2 |
source | src |
created_at | 2020-10-16 04:48:12.093769 |
updated_at | 2020-10-16 05:07:28.257132 |
description | Generates simple constructors for structs. |
homepage | |
repository | https://github.com/joshua-maros/scones |
max_upload_size | |
id | 300345 |
size | 17,959 |
A crate for quick and powerful constructor/builder generation in Rust. Dual
licensed under MIT OR Apache-2.0
. Example:
use scones::{make_builder, make_constructor};
#[make_builder]
#[make_constructor]
struct Basic {
int: i32,
string: String,
}
let instance = Basic::new(int, string);
let instance = BasicBuilder::new().string("str".to_owned()).int(12345).build();
// Triggers a compile-time error because we have not specified all fields yet:
// let instance = BasicBuilder::new().build();
#[make_constructor]
#[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(true)]
#[value(false for new)]
pub identical: bool,
}
let instance = MultipleConstructors::new(1, 2, 3);
let instance = MultipleConstructors::new_identical(123);
#[make_constructor]
#[make_constructor(pub default_number)]
#[make_builder((field_1?))]
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();