-
Notifications
You must be signed in to change notification settings - Fork 70
Open
Description
If you have a simple struct with two fields of the same type and use yaserde_derive, two identical visitors will be generated for these.
Example:
#[derive(YaDeserialize)]
pub struct XmlStruct {
#[yaserde]
num1: u32,
#[yaserde]
num2: u32,
}Using cargo expand shows that two visitors are generated
#[allow(non_snake_case, non_camel_case_types)]
struct __Visitor_Num1_;
impl<'de> ::yaserde::Visitor<'de> for __Visitor_Num1_ {
type Value = u32;
fn visit_u32(
self,
v: &str,
) -> ::std::result::Result<Self::Value, ::std::string::String> {
u32::from_str(v).map_err(|e| e.to_string())
}
}
#[allow(non_snake_case, non_camel_case_types)]
struct __Visitor_Num2_;
impl<'de> ::yaserde::Visitor<'de> for __Visitor_Num2_ {
type Value = u32;
fn visit_u32(
self,
v: &str,
) -> ::std::result::Result<Self::Value, ::std::string::String> {
u32::from_str(v).map_err(|e| e.to_string())
}
}I believe the derive macro should only create implementations for the YaDeserialize trait of unknown types. Instead yaserde should have implementations for default visitors similar to serde.
Furthermore I think it would be good, if the primitives have an implementation for the YaDeserialize trait
Metadata
Metadata
Assignees
Labels
No labels