Cannot find attribute `serde` in this scope?

Hello everyone :wave:

So I have in main.rs something like this :

#[macro_use] extern crate serde;
#[macro_use] extern crate serde_json;

And in a mod.rs file I have something like this :

use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
pub struct Monitor {
    /* A few field */
    #[serde(skip)]
    pub thread_wrapper: Option<ThreadWrapper>
}

But then I receive the error message "cannot find attribute serde in this scope" when I try to compile my program. Any idea on how to solve that ?

You did not #[derive(Serialize)] (or Deserialize) on your struct.

That's not the problem, I want serde to skip serealization on that field because that struct is field is NOT serializable. And again, the error is not about unimplemented traits.

EDIT : if you meant on the "parent" struct, I did add #[derive(Serialize, Deserialize)], I just didn't include it

EDIT : I edited my original post to include it.

My whole error looks like this :

error: cannot find attribute `serde` in this scope
  --> src\monitor\mod.rs:52:7
   |
52 |     #[serde(skip)]
   |       ^^^^^

Make sure you're using a recent version of serde (run cargo update). Also, you need to have the derive feature of serde enabled, if you don't, you should also have an error for "unrecognized derive".

If you don't have an "unrecognized derive" error, are running a recent version of serde_derive, and have the "unrecognized attribute serde" error, then you don't have the derive attribute on that struct.

Here are my dependencies :

[dependencies]
rocket = "0.4.5"
serde = { version = "1.0.115", features = ["derive"] }
lazy_static = "1.4.0"
serde_json = "1.0.57"

[dependencies.rocket_contrib]
version = "0.4.5"
default-features = false
features = ["tera_templates", "serve", "json"]

They are all updated, and I do have #[derive(Serialize, Deserialize)] on the struct.
As you can see, there's no serde_derive in my dependencies, but I though the derive feature would suffice

I have serde_derive in my Cargo.toml, and everything works. Try adding it.

Tried adding serde_derive, still the same error

The documentation at https://serde.rs/attr-skip-serializing.html says it's

#[serde(skip_serializing)].

If that fixes your problem, you should report it as a bad error message.

No it doesn't fix the problem. In fact, it's the first thing I've tried

And according to the serde doc, this serde(skip) should be the same as serde(skip_serializing, skip_deserializing)

It works now and I don't really know why

Glad to hear it, because both skip and skip_serializing work for me. Of course, I always worry when things fix themselves.

I probably had made a typo somewhere that got fixed by continuously rewriting my code.