Skip to content

Deserialize a field to an empty Vec<> #330

@ldicarlo

Description

@ldicarlo

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![],
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions