Skip to content

Update builder.md #433

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Update builder.md #433

wants to merge 1 commit into from

Conversation

nicsalv
Copy link

@nicsalv nicsalv commented Mar 31, 2025

Cite advantage about code extension use-case and the fact that Rust does not support default values for function parameters.

Cite advantage about code extension use-case and the fact that Rust does not support default values for function parameters.
@@ -73,6 +73,9 @@ Prevents proliferation of constructors.

Can be used for one-liner initialisation as well as more complex construction.

When the target struct is updated with new fields, the builder can be updated
to leave client code correct without changes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what this means

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imagine you have a custom type (the target struct) that you want to extend with new behaviour. You would like to add new behaviour and use it in new code, without modifying existing legacies. Since the builder pattern encapsulates the construction logic, it's possible to update the builder so that new fields can be used in new code while safely ignored in older usages.

Comment on lines +87 to +89
many other languages because Rust lacks overloading and default values for
function parameters. Since you can only have a single method with a given name,
having multiple constructors is less nice in Rust than in C++, Java, or others.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change looks good 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants