diff --git a/README.md b/README.md index b1c5727d..ce46abe2 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,11 @@ fn example() -> Result<(), Box> { // The iterator yields Result, 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(()) } diff --git a/examples/cookbook-read-basic.rs b/examples/cookbook-read-basic.rs index a69b0e2d..40f1b5f8 100644 --- a/examples/cookbook-read-basic.rs +++ b/examples/cookbook-read-basic.rs @@ -7,9 +7,13 @@ fn example() -> Result<(), Box> { let mut rdr = csv::Reader::from_reader(io::stdin()); for result in rdr.records() { // The iterator yields Result, 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(()) } diff --git a/src/cookbook.rs b/src/cookbook.rs index a28dc723..1eca694c 100644 --- a/src/cookbook.rs +++ b/src/cookbook.rs @@ -40,9 +40,13 @@ fn example() -> Result<(), Box> { let mut rdr = csv::Reader::from_reader(io::stdin()); for result in rdr.records() { // The iterator yields Result, 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(()) } @@ -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 diff --git a/src/lib.rs b/src/lib.rs index 3c771c95..f5001aea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,7 +76,11 @@ fn example() -> Result<(), Box> { // The iterator yields Result, 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(()) }