From e47be7c2887a5290c0b07107014bdb82907f0850 Mon Sep 17 00:00:00 2001 From: Maxwell Huang-Hobbs Date: Sun, 29 Sep 2024 05:53:27 +0000 Subject: [PATCH] nanoserde: ron: fix rust 2024 warning when using nserde(skip) field annotation --- derive/src/serde_ron.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/derive/src/serde_ron.rs b/derive/src/serde_ron.rs index 01d87e0..0f0bc60 100644 --- a/derive/src/serde_ron.rs +++ b/derive/src/serde_ron.rs @@ -200,23 +200,34 @@ pub fn derive_de_ron_named( )); } } else { - unwraps.push(default_val.unwrap_or_else(|| String::from("Default::default()"))); + unwraps.push(format!( + "{{ {} }}", + default_val + .as_ref() + .map(|x| x.as_str()) + .unwrap_or_else(|| "Default::default()") + )); } struct_field_names.push(struct_fieldname); ron_field_names.push(ron_fieldname); - local_vars.push(localvar); + local_vars.push((localvar, field.ty.full())); } let mut local_lets = String::new(); - for local in &local_vars { - l!(local_lets, "let mut {} = None;", local) + for (local, local_type) in &local_vars { + l!( + local_lets, + "let mut {}: Option<{}> = None;", + local, + local_type + ) } let match_names = if ron_field_names.len() != 0 { let mut inner = String::new(); - for (ron_field_name, local_var) in ron_field_names.iter().zip(local_vars.iter()) { + for (ron_field_name, (local_var, _)) in ron_field_names.iter().zip(local_vars.iter()) { l!( inner, "\"{}\" => {{