Serde: "cannot find derive macro `Deserialize/Serialize` in this scope"

I have imported serde for using the bincode crate, But the compiler is treating the Deserialize/Serialize macros like they do not exist.

Here is the code:

use serde::Serialize;
use serde::Deserialize;

#[derive(Copy, Clone, Serialize, Deserialize, PartialEq, Debug)]
struct Tile {
	id: usize,
	durability: u8,
}  

And here is the error:



error: cannot find derive macro `Serialize` in this scope
  --> src/main.rs:35:23
   |
35 | #[derive(Copy, Clone, Serialize, Deserialize, PartialEq, Debug)]
   |                       ^^^^^^^^^
   |
note: `Serialize` is imported here, but it is only a trait, without a derive macro
  --> src/main.rs:16:5
   |
16 | use serde::Serialize;
   |     ^^^^^^^^^^^^^^^^

error: cannot find derive macro `Deserialize` in this scope
  --> src/main.rs:35:34
   |
35 | #[derive(Copy, Clone, Serialize, Deserialize, PartialEq, Debug)]
   |                                  ^^^^^^^^^^^
   |
note: `Deserialize` is imported here, but it is only a trait, without a derive macro

I have tried importing the macros using use serde::macros::*;, But it's a private module, So I cannot use it.

1 Like

Make sure the derive feature on serde is enabled in your Cargo.toml

serde = { version = "1.0", features = ["derive"] }

8 Likes

Sorry about this, As I have never used serde before.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.