-
-
Notifications
You must be signed in to change notification settings - Fork 219
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
Confusing relationship between has_headers
and set_headers
#275
Comments
Please provide a complete program, along with the input, that I can compile and build that reproduces your problem. |
The example below shows the issue. Notice the parsing generates two items instead of just one, despite The question is what should happen when both
Two examples of bogus headers we're dealing with, where this behavior would help:
Cargo.toml:
main.rs:
|
I can't make heads or tails of the problem you're facing, sorry. The program you've given me runs just fine. So what's the issue here exactly? |
Yes, please remove the first element of the |
Ah I see. Yeah, this is documented behavior. As the docs for
The issue here is that your CSV file does have headers. You just don't want them. You want to set your own. So you should set
Then your program works, with the first record omitted the assertions below pass. Thinking on this a bit more, I think I understand the issue here. Namely, that if Maybe this deserves to be an example in the docs. |
Thanks for taking the time to look into this! Yes, the implication of my request is that it skips the first row when both In the example above when
|
Because your header row doesn't fit into your serde type. There is no inconsistency here. In one case, you're trying to deserialize it into your type. In the other case, you're just reading it as a plain string record. Why doesn't the code i have you work for you? |
The issue I see boils down to the weirdness between For example:
The output makes sense when Notice the third result
Mentioning the |
Maybe assert in |
The output when
The errors make sense except the last one: "UnexpectedEndOfRow". Mentioning as it might be a potential source of confusion. |
This is a breaking change. I agree that it is weird to call I think the fundamental confusion here is that you're trying to form a connection between But yeah, if you're setting I'll mark this as a |
has_headers(true)
has_headers
and set_headers
Thanks for considering to improve the documentation. When using custom deserialization for custom field types it can be super confusing seeing the headers set with How bad would it be to introduce a breaking change? This usage does not make any sense at all. :) Users can select any release they want if they prefer the past functionality. |
This confusion does not come anywhere remotely close to being bad enough to justify a breaking change or a You've made it clear this behavior is confusing to you and that you don't like it. I understand. Let's improve the docs and move on. If and when there's ever a
It makes sense just fine if you consider that using |
I'm just curious how you think. Ok, good luck! |
What version of the
csv
crate are you using?csv = "1.1.6"
Briefly describe the question, bug or feature request.
The header line is parsed as the rest of the lines, when it should not be parsed. This results in failure when the column names are parsed and validated with serde.
Include a complete program demonstrating a problem.
I need to use the following workaround to make it work:
This is the CSV:
Does not matter that
has_headers
is set totrue
orfalse
, seems broken.Also, note if I'm not manually skipping the first line,
"name"
is also parsed despite usingset_headers()
and despitehas_headers(true)
, seems a different issue?The text was updated successfully, but these errors were encountered: