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

Add "read csv records" #320

Merged
merged 1 commit into from Oct 8, 2017

Conversation

Projects
None yet
2 participants
@ludwigpacifici
Copy link
Contributor

ludwigpacifici commented Oct 7, 2017

fixes #228

@budziq
Copy link
Collaborator

budziq left a comment

Nice! @ludwigpacifici

Only sone minor stylistic suggestions and we are ready to merge!

}
#[derive(Debug, Deserialize)]
struct Record {

This comment has been minimized.

@budziq

budziq Oct 7, 2017

Collaborator

I would move the struct definition to the beginning of the snippet. this will improve the reading flow somewhat


[![csv-badge]][csv] [![cat-encoding-badge]][cat-encoding]

Reads standard CSV records into [`csv::StringRecord`] (valid UTF-8 bytes).

This comment has been minimized.

@budziq

budziq Oct 7, 2017

Collaborator

(valid UTF-8 bytes).

the meaning of this last part is unclear. Could you elaborate the description?

This comment has been minimized.

@ludwigpacifici

ludwigpacifici Oct 8, 2017

Author Contributor

From the documentation: https://docs.rs/csv/1.0.0-beta.4/csv/struct.StringRecord.html

A string record permits reading or writing CSV rows that are valid UTF-8. [...] If you do need to read possibly invalid UTF-8 data, then you should prefer using a ByteRecord, since it makes no assumptions about UTF-8.

Is it part of the cookbook to paraphrase the rust/crates documentation? I think it is not a good idea to duplicate it, and actually I prefer to remove:

(valid UTF-8 bytes).

The reader can follow the link for more precise and up to date documentation.

This comment has been minimized.

@budziq

budziq Oct 8, 2017

Collaborator

Hmm it might be quite surprising to the users that their valid csv will not work with this example due to uncommon encoding. As this is the most basic csv example it should be the most informative and ordered as first (we will reorder the deserialization examples later on). I would actually suggest to mentioning this distinction between StringRecord and ByteRecord.

This comment has been minimized.

@ludwigpacifici

ludwigpacifici Oct 8, 2017

Author Contributor

Make sense. Should it be mentioned in the description and in an additional snippet?

This comment has been minimized.

@budziq

budziq Oct 8, 2017

Collaborator

the end of the main description should be enough but I'll leave it up to you to put it where it will make mist sense

This comment has been minimized.

@ludwigpacifici

ludwigpacifici Oct 8, 2017

Author Contributor

I will mention it in the description. However, the extra snippet is not useful. In the first example code, it's only a matter of replacing from for record in reader.records() { to for record in reader.byte_records() {

This comment has been minimized.

@budziq

budziq Oct 8, 2017

Collaborator

I wouldn't say that the second snippet is not useful. But handling non UTF-8 data there would be more involved so lets leave it as its is.

for record in reader.deserialize() {
let record: Record = record?;
println!("{:?}", record);

This comment has been minimized.

@budziq

budziq Oct 7, 2017

Collaborator

how about we emphasize the strongly typed nature of the deserialization by also using one of the fields directly?

This comment has been minimized.

@ludwigpacifici

ludwigpacifici Oct 8, 2017

Author Contributor

Good idea

let mut reader = csv::Reader::from_reader(csv.as_bytes());
for record in reader.records() {
println!("{:?}", record?);

This comment has been minimized.

@budziq

budziq Oct 7, 2017

Collaborator

how about we emphesize the dynamic nature of this variant by using the record fields by its index?

This comment has been minimized.

@ludwigpacifici

ludwigpacifici Oct 8, 2017

Author Contributor

Yes, good idea

@budziq budziq merged commit 8c80e34 into rust-lang-nursery:master Oct 8, 2017

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@budziq

This comment has been minimized.

Copy link
Collaborator

budziq commented Oct 8, 2017

@ludwigpacifici Nicely done!
I'll just remove the derive debug as it is no longer needed when cleaning up/reordering the csv examples

@ludwigpacifici

This comment has been minimized.

Copy link
Contributor Author

ludwigpacifici commented Oct 8, 2017

It's a pleasure! Thanks for your reviews @budziq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.