Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate visitors with yaserde_derive #198

Open
NiklasVousten opened this issue Oct 31, 2024 · 0 comments
Open

Duplicate visitors with yaserde_derive #198

NiklasVousten opened this issue Oct 31, 2024 · 0 comments

Comments

@NiklasVousten
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant