$ cargo check
Checking exp v0.1.0 (folder path)
error: cannot find derive macro `Deserialize` in this scope
--> src\main.rs:3:28
|
3 | #[derive(Debug, Serialize, Deserialize)]
| ^^^^^^^^^^^
error: cannot find derive macro `Serialize` in this scope
--> src\main.rs:3:17
|
3 | #[derive(Debug, Serialize, Deserialize)]
| ^^^^^^^^^
warning: unused imports: `Deserialize`, `Serialize`
--> src\main.rs:1:13
|
1 | use serde::{Serialize, Deserialize};
| ^^^^^^^^^ ^^^^^^^^^^^
|
= note: #[warn(unused_imports)] on by default
error[E0277]: the trait bound `for<'de> SomeData: serde::de::Deserialize<'de>` is not satisfied
--> src\main.rs:15:45
|
15 | let response_json: SomeData = match res.json() {
| ^^^^ the trait `for<'de> serde::de::Deserialize<'de>` is not implemented for `SomeData`
|
= note: required because of the requirements on the impl of `serde::de::DeserializeOwned` for `SomeData`
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0277`.
error: Could not compile `exp`.
The error says "cannot find derive macro Deserialize in this scope". Serde's derive macros are provided by serde_derive, so you have to add that crate as a dependency and import the derive macros with use serde_derive::{Serialize, Deserialize};. Importing a derive macro allows you to use it in #[derive(...)] attributes.
On the other hand, serde::{Serialize, Deserialize} are traits, not derive macros. Importing a trait allows you to use functions from this trait, as well as use them by their identifier directly. You can import derive macros and traits with the same name in the same scope if you need.
$ cat Cargo.toml
[package]
name = "exp"
version = "0.1.0"
authors = ["sprkv5"]
edition = "2018"
[dependencies]
reqwest = "0.9"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Thus, I accepted the answer by Idesgoui. It was precise at pointing out what I was missing.
On the other hand, using feature flags basically means enabling crates. In this case serde_derive Riateche your answer implies that.