colin-kiegel / rust-derive-builder

derive builder implementation for rust structs
https://colin-kiegel.github.io/rust-derive-builder/
Apache License 2.0
1.28k stars 82 forks source link

Document #[builder(setter(custom))] option #224

Closed rezaalavi closed 2 years ago

rezaalavi commented 2 years ago

I would like to be able to opt-out of the setter generation for certain fields so that I can write my own setters,

Lets say I have the following struct:

#[derive(Debug, Default,Builder )]
pub struct Email{
    username:String,
    domain: String,
    #[builder(setter(skip))]
    password: String,
    quota: u64,

and I want to have the following code for the password setter:

impl EmailBuilder {
    pub fn with_password(&mut self, password: String) -> &mut Self {
        self.password = Some( pwhash::bcrypt::hash(password).unwrap());
        self
    }

The current implementation for the "setter(skip)" changes the 'password' field type to "PhantomData" which is not usable.

TedDriggs commented 2 years ago

This exists as #[builder(setter(custom))], but is not documented well (or at all?)