1
1
mirror of https://github.com/wez/wezterm.git synced 2025-01-08 23:17:36 +03:00

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 2022-05-20 13:38:24 -07:00
parent b312479266
commit 94039c473b

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<_>>();