-
Notifications
You must be signed in to change notification settings - Fork 84
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
#[builder(default)] on struct-level does not use Default impl of the struct #61
Comments
This is an interesting proposal, but it would be a breaking change. Right now #[derive(Builder)]
pub struct Example {
#[builder(default)]
pub a_flag: bool,
#[builder(default)]
pub limit: Option<String>,
#[builder(default)]
pub third: String,
} I think the current meaning can also be useful in some cases. I'm not sure which one is more important and I would like to hear more opinions about it. cc @killercup do you have an opinion about this? |
I'd interpreted this comment on #3 to mean emulating serde's behavior, which does use the |
After looking at this some more, I don't think the current implementation should be considered valid behavior. The following assertion seems expected for any type: assert_eq!(Ok(Example::default()), ExampleBuilder::default().build()); Worse still, #[derive(Debug, Clone, Builder)]
#[builder(default)]
struct Outer {
inner: Example
} then the invariant I wrote above holds, because derive_builder's current If this change gets made quickly enough, then there won't have been much time for people to take a dependency on the wrong behavior. The current behavior could be opted into by adding a second method to the builder Update: I'm trying to work on a pull request for this; haven't worked with proc macros before, so it may be a little rough. Hoping to send a PR out soon. |
Ok, you've convinced me that there are strong reasons to change the behaviour. Especially the precedence case of serde was already very convincing. :-) I thought about how to introduce this change and came up with this:
This compatibility-dance adds a little complexity to the actual implementation, but I'd be willing to do it, if only for practising it. :-) Btw. thank you very much for starting the implementation! 👍 |
I'll give it a shot this afternoon; I think I know how to do everything except for the deprecation warning on usage-without-cfg flag. |
released v0.4.1, which deprecates the old behaviour and offers an opt-in to the new behaviour via |
rustc version: 1.17.0-nightly (6eb9960d3 2017-03-19)
derive_builder version: 0.4.0
When a struct has a non-derived
impl Default
, those values do not get used in the output of the builder.Repro
This panics with the following error:
Expected: The resulting structs are equal.
The text was updated successfully, but these errors were encountered: