Skip to content

Is there a way to get a builder for a struct ? #99

Answered by idanarye
cameronbraid asked this question in Q&A
Discussion options

You must be logged in to vote

This crate does not support it, and I don't think it should.

Typed Builder's first and foremost purpose is to allow fields with default values to get their default values while ensuring, at compile time, that all the mandatory fields are set. If you create a builder from a struct, all the fields are already set - making this enforcement redundant.

Typed Builder also verifies that no field is set in the builder more than once. This is actually a problem in your case - if the builder is initialized by the original struct, then any field you set in it will be set a second time. Of course, this can be resolved by deciding that fields can be set once in the builder in addition to being initial…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by cameronbraid
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants