Reading CSV data from URI and putting it in a struct

Trying to read COVID-19 data and putting it in a struct, the data is here:
showing cases recorded every day.

I tried the below:

serde = { version = "1.0.105", features = ["derive"] }
reqwest = { version = "0.10", features = ["json"] }
tokio = { version = "0.2", features = ["full"] }
csv = "1.1.3"


use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
struct Record {
    Province: str,
    Country: str,
    Lat: f64,
    Long: f64,
    d001: i32,    d002: i32,    d003: i32,     d004: i32,     d005: i32,     d006: i32,     d007: i32,    d008: i32,    d009: i32,
    d010: i32,    d011: i32,    d012: i32,     d013: i32,     d014: i32,     d015: i32,     d016: i32,    d017: i32,    d018: i32,
    d019: i32,    d020: i32,    d021: i32,     d022: i32,     d023: i32,     d024: i32,     d025: i32,    d026: i32,    d027: i32,
    d028: i32,    d029: i32,    d030: i32,     d031: i32,     d032: i32,     d033: i32,     d034: i32,    d035: i32,    d036: i32,
    d037: i32,    d038: i32,    d039: i32,
    d040: i32,    d041: i32,    d042: i32,     d043: i32,     d044: i32,     d045: i32,    d046: i32,    d047: i32,    d048: i32,
    d049: i32,    d050: i32,    d051: i32,     d052: i32,     d053: i32,     d054: i32,    d055: i32,    d056: i32,    d057: i32,
    d058: i32,    d059: i32,    d060: i32,

async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let res = reqwest::get("").await?;

    println!("Status: {}", res.status());

    let body = res.text().await?;
      //  println!("Body:\n\n{}", body);

    let mut reader = csv::Reader::from_reader(body.as_bytes());

    for result in reader.deserialize() {
        // The iterator yields Result<StringRecord, Error>, so we check the
        // error here.
        let record: Record = result?;
        println!("{:?}", record);

But when I compiled it, I got the below error:

error: There are multiple `csv` packages in your project, and the specification `csv` is ambiguous.
Please re-run this command with `-p <spec>` where `<spec>` is one of the following:

Process finished with exit code 101

Did you name your own package "csv"? If so, try changing the package name in Cargo.toml, or use -p csv:0.1.0 to refer to your own package.

If not, do you still get the same behavior after running cargo clean and cargo update? If you look in the Cargo.lock file, what package depends on csv 0.1.0?

If that doesn't help, please share the entire Cargo.toml file.

1 Like

Thanks, you are correct, my package name is csv, I changed it, then I run cargo clean

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.