Merge pull request #176 from marcelbuesing/add_struct_name_to_required_field_error

Add struct name to required field error
This commit is contained in:
Marc-Antoine ARNAUD 2024-02-06 21:35:47 +01:00 committed by GitHub
commit ef9da1b7ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -347,11 +347,12 @@ pub fn parse(
quote! { #label: #value_label.unwrap_or_else(|| #default_function()), } quote! { #label: #value_label.unwrap_or_else(|| #default_function()), }
} else { } else {
let error = format!( let error = format!(
"{} is a required field", "{} is a required field of {}",
label label
.as_ref() .as_ref()
.map(|label| label.to_string()) .map(|label| label.to_string())
.unwrap_or_default() .unwrap_or_default(),
name
); );
quote! { #label: #value_label.ok_or_else(|| #error.to_string())?, } quote! { #label: #value_label.ok_or_else(|| #error.to_string())?, }