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 slightly more detail about StringRecord in examples #242

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ fn example() -> Result<(), Box<dyn Error>> {
// The iterator yields Result<StringRecord, Error>, so we check the
// error here.
let record = result?;
println!("{:?}", record);

// Records can be indexed like a vector to return single strings
let cell: &str = &record[0];

println!("The first cell is {:?}", cell);
}
Ok(())
}
Expand Down
8 changes: 6 additions & 2 deletions examples/cookbook-read-basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ fn example() -> Result<(), Box<dyn Error>> {
let mut rdr = csv::Reader::from_reader(io::stdin());
for result in rdr.records() {
// The iterator yields Result<StringRecord, Error>, so we check the
// error here..
// error here.
let record = result?;
println!("{:?}", record);

// Records can be indexed like a vector to return single strings
let cell: &str = &record[0];

println!("The first cell is {:?}", cell);
}
Ok(())
}
Expand Down
10 changes: 8 additions & 2 deletions src/cookbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ fn example() -> Result<(), Box<dyn Error>> {
let mut rdr = csv::Reader::from_reader(io::stdin());
for result in rdr.records() {
// The iterator yields Result<StringRecord, Error>, so we check the
// error here..
// error here.
let record = result?;
println!("{:?}", record);

// Records can be indexed like a vector to return single strings
let cell: &str = &record[0];

println!("The first cell is {:?}", cell);
}
Ok(())
}
Expand All @@ -55,6 +59,8 @@ fn main() {
}
```

For more information on how to use a `StringRecord` object, refer its [API page](../struct.StringRecord.html).

The above example can be run like so:

```ignore
Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ fn example() -> Result<(), Box<dyn Error>> {
// The iterator yields Result<StringRecord, Error>, so we check the
// error here.
let record = result?;
println!("{:?}", record);

// Records can be indexed like a vector to return single strings
let cell: &str = &record[0];

println!("The first cell is {:?}", cell);
}
Ok(())
}
Expand Down