Use of undeclared crate or module

Viewed 2659

I am getting the following error when I use serde to read a json from a file:

Failed to resolve: use of undeclared crate or module serde_json

here's the code:

use serde::Deserialize;


fn main() {
  let file = fs::File::open("./feed.json")
      .expect("file should open read only");
  let reader = BufReader::new(file);
  let json = serde_json::from_reader(reader)
      .expect("file should have FirstName key");
  let feed_url = json.get("2.0")
      .expect("file should have FirstName key");
  println!("{}", reedFeed(feed_url));
}

Here's the doc on this function. I am on ubuntu and using intellij as my ide. What am I missing here?

1 Answers

As @Dogbert said, add serde = "1.0.136" and serde_json = "1.0.79" to the end of your Cargo.toml (under "[dependencies]"). This will tell cargo to download the dependencies on the next cargo run and use it from that point on.

Related