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

No error, when there are no items in CSV file during struct deserializing (with serde) #272

Open
codercengiz opened this issue Apr 4, 2022 · 3 comments

Comments

@codercengiz
Copy link

Problem:

When deserializing a CSV file with only headers without any other rows into a struct (with serde), It doesn't give any error, and the records count is 0.

In this case, it may give an error, and can be stated that there must be at least one item in the csv file

@codercengiz codercengiz changed the title No error, when there are no items in CSV file during struct deserializing No error, when there are no items in CSV file during struct deserializing (with serde) Apr 4, 2022
@BurntSushi
Copy link
Owner

An empty CSV file (including a CSV file with a single header row) is a valid CSV file. If it doesn't work for your specific use case, then your code should return an error. I don't see a reason why this crate should return an error.

Also, I don't know what serde has to do with this. It seems orthogonal.

@codercengiz
Copy link
Author

codercengiz commented Apr 4, 2022

Yes, you are right, but this issue is more about headers. I think I misdescribed the problem.

In this case, it does not give an error even if the headers are not compatible with the struct,

for example struct structure:

pub struct ProductCreate {
    pub model: String,
    pub brand: String,
    pub description: Option<String>,
    pub classification: Option<String>,
    pub sales_type: Option<String>,
}

example csv:
model;description;classification;sales_type it has only headers row without brand
Expected error: must exist model header

One more example csv file:
firstname;lastname;email it has only headers but is completely different from the struct.
Expected error: must exist model and brand headers

I think, In this case, it would be better to have an error.

@BurntSushi
Copy link
Owner

BurntSushi commented Apr 4, 2022

I don't think this is possible to implement with serde.

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