unit structs variants may now omit "content" in from_value

This commit is contained in:
Tim 'Piepmatz' Hesse 2024-06-01 20:56:49 +02:00
parent 16f85e49ff
commit a14ea9c2ca

View File

@ -144,13 +144,11 @@ fn enum_from_value(data: &DataEnum) -> TokenStream2 {
})?; })?;
let ty = ty.into_string()?; let ty = ty.into_string()?;
// TODO: make content optional if type refers to a unit variant // This allows unit variants to resolve without the "content" field
// in the record.
let v = record.remove("content").ok_or_else(|| nu_protocol::ShellError::CantFindColumn { let v = record
col_name: std::string::ToString::to_string("content"), .remove("content")
span: call_span, .unwrap_or_else(|| nu_protocol::Value::nothing(span));
src_span: span
})?;
match ty.as_str() { match ty.as_str() {
#(#arms),* #(#arms),*