rust-csv icon indicating copy to clipboard operation
rust-csv copied to clipboard

Deserialize a field to an empty Vec<>

Open ldicarlo opened this issue 2 years ago • 0 comments

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

ldicarlo avatar Jul 24 '23 20:07 ldicarlo