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:
1 parent
b312479266
commit
94039c473b
1 file changed
+6
-7
@@ -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<_>>();
|
||||
|
||||
Reference in new issue
Block a user