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

Deserialize a field to an empty Vec<> #330

Open
ldicarlo opened this issue Jul 24, 2023 · 0 comments
Open

Deserialize a field to an empty Vec<> #330

ldicarlo opened this issue Jul 24, 2023 · 0 comments

Comments

@ldicarlo
Copy link

ldicarlo commented Jul 24, 2023

Hello, thank you for this crate, I use it a lot. (a lot, and out of just deserializing csv actually).

Thank you for taking the time to answer.

What version of the csv crate are you using?

1.2.2

Briefly describe the question, bug or feature request.

I wonder if it is possible to deserialize an empty vec.

Include a complete program demonstrating a problem.

Taking directly from the documentation here

    #[test]
    fn example() -> Result<(), Box<dyn Error>> {
        let data = "foo";
        let mut rdr = ReaderBuilder::new()
            .has_headers(false)
            .from_reader(data.as_bytes());
        let mut iter = rdr.deserialize();

        if let Some(result) = iter.next() {
            let record: Row = result?;
            assert_eq!(
                record,
                Row {
                    label: "foo".to_string(),
                    values: vec![],
                }
            );
            Ok(())
        }
    }

What is the observed behavior of the code above?

I edited a little bit your example in the Rules section, because I am working on a case where the list can be empty.

What is the expected or desired behavior of the code above?

I would like to see a

Row {
    label: "foo".to_string(),
    values: vec![],
}

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