Build from#391
Open
BernardIgiri wants to merge 12 commits into
Open
Conversation
- Changed logic for build_from and build_from_clone, so that cloning only happens in the latter and the former just takes ownership. - Added support for function methods. - Added tests to cover more builder use cases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
build_fromandbuild_from_clonebuilder methodsCloses #310
This PR is a fresh continuation of the original #313 , which I accidentally closed when rebasing my master branch. I have since transplanted my work on here:
Original PR Overview
This PR adds support for two new optional top-level builder attributes:
#[builder(build_from)]– Adds a.build_from(T)/.call_from(T)method (takesTby value).#[builder(build_from_clone)]– Adds a.build_from_clone(&T)/.call_from_clone(&T)method (takes&Tand clones fields).These methods allow partially configured builders to fill in missing fields from an existing instance of the target type before finalizing the build. This is useful when:
Default, making field reuse non-trivial.Example
Rust
Implementation Notes
builder_gen/build_from.rsand is conditionally compiled/emitted via theexperimental-build-fromfeature flag.ItemSigConfigdirectly intodarling::FromMetaallows native attribute parsing without structural wrapper types.Default::default().WIP Status & Next Steps
This PR is currently open as a Draft / WIP. Before marking it ready for full review, I am working on polishing a few key items:
vis) and documentation (doc) passed inside#[builder(build_from(...))]are properly inherited by the generated methods.bonwhen applied to functions or associated methods (ensuring we invoke the execution block rather than blindly emitting a structural literal path).