moy2010
moy2010

Reputation: 900

Error E0412: use of undeclared crate or module `tokio` when importing tokio::sync

In my rust project, cargo complains about a used type not being in scope when using tokio::sync:

use tokio::sync::RwLock;
  |     ^^^^^ use of undeclared crate or module `tokio`

but it clearly is in scope:

use tokio::sync::RwLock;

#[derive(Deserialize, Serialize)]
pub struct MyStruct {
    some_field: RwLock<SomeType>
}

According to the documentation, the sync module is only available after enabling the sync feature flag, which I have done both explicitly and implicitly:

tokio = { version = "0.3", features = ["macros", "sync"] }
tokio = { version = "0.3", features = ["full"] }

But it does not work with either.

Upvotes: 1

Views: 8550

Answers (1)

moy2010
moy2010

Reputation: 900

I didn't notice that I only had tokio under the dev-dependencies, which is why cargo was not able to compile the project.

Upvotes: 2

Related Questions