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

csv_vectors example doesn't work #83

Open
Gordon01 opened this issue May 24, 2023 · 2 comments
Open

csv_vectors example doesn't work #83

Gordon01 opened this issue May 24, 2023 · 2 comments

Comments

@Gordon01
Copy link
Contributor

I've added a test in this PR #82 which highlights the problem:

thread 'deserialize_sequence' panicked at 'assertion failed: `(left == right)`
  left: `Query { r: [], s: 12 }`,
 right: `Query { r: [1, 2, 3], s: 12 }`', examples\csv_vectors.rs:32:5
@samscott89
Copy link
Owner

Oof, thanks for finding that and raising!

Would you be up for working on a fix?

@Gordon01
Copy link
Contributor Author

Unfortunately, I couldn't make it to work due to my relatively low experience with serde.
I've just made an ad-hoc solution that worked in my case:

        fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
        where
            E: de::Error,
            <T as FromStr>::Err: fmt::Display,
        {
            v.split(',')
                .map(|i| i.parse::<T>().map_err(E::custom))
                .collect()
        }

I would be much happier in making a PR, adding such functionality into serde_qs itself because too many people need such a parser for sequences.
Something like a:

#[derive(Serialize, Deserialize)]
struct Users {
    #[serde_qs(value_delimiter = ",")]
    users: Vec<u64>,
}

instead of

#[derive(Serialize, Deserialize)]
struct Users {
    #[serde(default, deserialize_with = "deserialize_list")]
    users: Vec<u64>,
}

would be much greater)

But I don't know how to code it right now (

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

2 participants