dynamic: allow defaulting to None for enum struct fields

refs: https://github.com/wez/wezterm/issues/1993#issuecomment-1133283042

```
DISPLAY=:0 ./target/debug/wezterm -n --config 'keys={{key="a", mods="NONE", action=wezterm.action{SwitchToWorkspace={ name = "default"}}}}'
```
This commit is contained in:
Wez Furlong committed 2022-05-20 13:38:24 -07:00
1 parent b312479266
commit 94039c473b
1 file changed
+6 -7
+6 -7
View File
@@ -210,14 +210,13 @@ fn derive_enum(input: &DeriveInput, enumeration: &DataEnum) -> Result<TokenStrea
let ty = &f.ty;
quote!(
#ident: <#ty>::from_dynamic(
obj.get_by_str(#name)
.ok_or_else(|| wezterm_dynamic::Error::ErrorInField {
type_name: #literal,
field_name: #name,
error: "missing field".to_string(),
})?,
obj.get_by_str(#name).unwrap_or(&Value::Null),
options
)?,
).map_err(|source| source.field_context(
#literal,
#name,
obj
))?,
)
})
.collect::<Vec<_>>();