Build from - #391
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
|
just saw this pr, got a suggestions. build_from_clone seems like a duplicate of build_from. if you have a builder where all the fields are clone, you can just implement Clone for the struct like its done in your example, then you can call .build_from(template.clone()). Another thing is that you should probably mark this pr as a draft pr (makes it easy to quickly see why a pr isnt merged). also isnt your pr description kind of weird. theres no need to inherit attributes or to write weird implementation details that don't make sense without looking at the code in the first place. you also mention .call_from when you never elaborate on what it is. please make it more sense xd |
|
Function-builder
User-configured
Per-member and
Unused
🔍 Reviewed by nitpicker |
|
I feel like im reading something written in riddles... Isnt ai supposed to be good at making people understand stuff? I feel like i am trying to read a raw slotmap and its entries instead of printing out a tree it represents, this response has the same exact vibe |
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).