Skip to content

Implement #[derive(Builder)] for automatically generating builders for the scoped struct #71

@FL03

Description

@FL03
use scsys::Builder;

#[derive(Builder)]
#[scsys(builder(ConfigBuilder))]
pub struct Config {
    eps: f64,
    name: String,
}

impl Config {
    pub fn new()-> ConfigBuilder {
        ConfigBuilder::new()
    }
}

/*
    ********* Generated *********
*/


pub struct ConfigBuilder {
    eps: f64,
    name: String,
}

impl ConfigBuilder {
    pub fn new() -> Self {
        Self {
            eps: 1e-5,
            name: String::new(),
        }
    }

    pub fn eps(mut self, eps: f64) -> Self {
        self.eps = eps;
        self
    }

    pub fn name(mut self, name: String) -> Self {
        self.name = name;
        self
    }

    pub fn build(self) -> Config {
        Config {
            eps: self.eps,
            name: self.name,
        }
    }
}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestmacroAny additions or improvements to procedural macrosrustImprovements or additions that update the Rust code

Type

No type

Projects

Status

👀 In review

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions