-
Notifications
You must be signed in to change notification settings - Fork 329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unify builders' patterns #2853
Comments
In some circumstances, taking |
@evenyag Can you demostrate the code? // &mut self
let mut builder = ...;
for ... {
builder.with_xxx(...);
}
// self
let mut builder = ...;
for ... {
builder = builder.with_xxx(...);
} In my illustration, those two flavor in loop seems quite similar. For add elements - pub struct Builder {
ns: Vec<u64>
}
impl Builder {
fn add_n(&mut self, n: u64) {
self.ns.push(n);
}
fn add_n(mut self, n: u64) -> Self {
self.ns.push(n);
self
}
} A possible argument is that not always the full ownership is easily to take. This decision happened also when I choose |
The assignment is annoying and looks different from other invocation of setters. let mut builder = RegionMetadataBuilder::new(self.region_id);
for column in &self.column_metadatas {
builder = builder.push_column_metadata(column.clone());
}
builder.primary_key(self.primary_key.clone()); We only use the assignment inside the for loop. However, it is just a minor style problem but not a blocker for this issue.
Yes, this is possible if we want to reuse the builder or work with a trait object (the MutableVector trait). However, it is possible to unify most builders. |
What type of enhancement is this?
Refactor
What does the enhancement do?
Currently we have a lot of builders with multiple patterns:
with_field_name
to set their values while others are usingfield_name
directly;&mut self
andself
differently;derive-builder
crate's builder or notTo make our codes look better, let's unify all these builders' patterns:
derive-builder
.typed-builder
looks more promising (see its "Alternatives" section in its readme)self
and returnself
with_field_name
Implementation challenges
No response
The text was updated successfully, but these errors were encountered: