I created an exact example code of my scenario. I'm trying to use the syntax for "autocompleted" fields that weren't defined explicitly in a new struct declaration. However, cargo throws me an error that doesn't really help much and it drives me nuts that I can't understand whats happening, however the example I created is working exactly as intended. I need to know what am I missing.
This is the example with the crates used:
use typed_builder::TypedBuilder;
use serde_derive::Serialize;
use serde_derive::Deserialize;
#[derive(Clone, Debug, Default, TypedBuilder, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
struct SomeStruct {
#[builder(default)]
#[serde(skip)]
field1: Option<bool>,
#[builder(default)]
field2: Option<u32>,
}
fn something(arg: Option<SomeStruct>) {
let var = SomeStruct {
field1: Some(true),
..arg.unwrap_or_default()
};
dbg!(var);
}
fn main() {
something(None);
}
From toml:
serde = "1.0.116"
serde_derive = "1.0.116"
typed-builder = "0.7.0"
So as I said the above is working, however in my code which is exactly structured like that, I'm getting:
error[E0639]: cannot create non-exhaustive struct using struct expression
|
266 | let var = SomeStruct {
| _________________________^
267 | | field1: Some(true),
268 | | ..arg.unwrap_or_default()
269 | | };
| |_________^
If it matters the count of fields in the struct is different in the real code.