While trying out some Rust exercises, I came across the following error:
$ cargo run --bin iter2
Compiling tutor-web-app-ssr v0.1.0 (/home/kenno/dev/rust/chapter7/ezytutors/tutor-web-app-ssr)
error: cannot find derive macro `Serialize` in this scope
--> tutor-web-app-ssr/src/bin/iter2.rs:17:10
|
17 | #[derive(Serialize, Deserialize)]
| ^^^^^^^^^
|
note: `Serialize` is imported here, but it is only a trait, without a derive macro
--> tutor-web-app-ssr/src/bin/iter2.rs:5:26
|
5 | use serde::{Deserialize, Serialize};
| ^^^^^^^^^
error: cannot find derive macro `Deserialize` in this scope
--> tutor-web-app-ssr/src/bin/iter2.rs:17:21
|
17 | #[derive(Serialize, Deserialize)]
<SNIP>
This happened because I didn’t specify the required dependency feature for serde
crate. Here is what I had in Cargo.toml
when the above error occurred:
[dependencies]
serde = { version = "1.0.202" }
To fix this, I need to enable the derive
feature of serde
as the following:
[dependencies]
serde = { version = "1.0.202", features = ["derive"] }
References: