Hello I'm new to rust. I've been reading the rust book and doing lots of research.
I'm attempting to add a rest API to Mozilla's Project Mentat. I think I've got most of the structure working but I'm running into issues in the query-projector crate.
Here is the first error
error[E0432]: unresolved import `serde`
--> query-projector/src/lib.rs:74:9
|
74 | pub use serde::Serialize;
| ^^^^^ maybe a missing crate `serde`?
The error index: Rust Compiler Error Index indicates that there may be a spelling mestake (checked) some difference due to rust edition (tried setting edition to 2021) no luck. I also double checked the cargo.toml in the query-projector crate.
query-projector/Cargo.toml
[package]
name = "mentat_query_projector"
version = "0.0.2"
workspace = ".."
[features]
sqlcipher = ["rusqlite/sqlcipher"]
[dependencies]
failure = "~0.1"
indexmap = "~1.7"
serde = { version = "~1.0", optional = true }
serde_derive = { version = "~1.0", optional = true }
serde_json = "~1.0"
[dependencies.rusqlite]
version = "~0.26"
features = ["limits", "bundled"]
[dependencies.core_traits]
path = "../core-traits"
[dependencies.edn]
path = "../edn"
[dependencies.mentat_core]
path = "../core"
[dependencies.mentat_db]
path = "../db"
[dependencies.db_traits]
path = "../db-traits"
[dependencies.mentat_query_algebrizer]
path = "../query-algebrizer"
[dependencies.mentat_query_pull]
path = "../query-pull"
[dependencies.query_pull_traits]
path = "../query-pull-traits"
[dependencies.query_projector_traits]
path = "../query-projector-traits"
[dependencies.mentat_query_sql]
path = "../query-sql"
[dev-dependencies.mentat_sql]
path = "../sql"
I've tried clearing the build cache removing cargo.lock files and continue to get the same error. Ideas?
Full source code here: GitHub - TechplexEngineer/mentat at web-server
Serde is an optional dependency; maybe you’ll want to put #[cfg(feature = "serde")] on that pub use … line (or on some module containing it).
Make sure to test whether the crate still works either with or without that feature (specify the feature by including or not including --features serde argument to cargo check or other cargo commands).
In case serde isn’t supposed to be an optional dependency at all, the Cargo.toml should be modified accordingly.
1 Like
If I change it to be a required dependency, here is the new cargo.toml:
[dependencies]
failure = "~0.1"
indexmap = "~1.7"
serde = { version = "~1.0", features = ["derive"] }
serde_derive = { version = "~1.0" }
serde_json = "~1.0"
I get the same error as above, all errors reproduced below:
error[E0432]: unresolved import `serde`
--> query-projector/src/lib.rs:75:9
|
75 | pub use serde::Serialize;
| ^^^^^ maybe a missing crate `serde`?
error: cannot determine resolution for the derive macro `Serialize`
--> query-projector/src/lib.rs:77:39
|
77 | #[derive(Clone, Debug, PartialEq, Eq, Serialize)]
| ^^^^^^^^^
|
= note: import resolution is stuck, try simplifying macro imports
error: cannot determine resolution for the derive macro `Serialize`
--> query-projector/src/lib.rs:83:39
|
83 | #[derive(Clone, Debug, PartialEq, Eq, Serialize)]
| ^^^^^^^^^
|
= note: import resolution is stuck, try simplifying macro imports
In case the code is still edition 2015, you’d also need to put extern crate serde; somewhere (I believe typically in the root module of the crate). In case of optional dependency, that would also need to be cfg’d, so
#[cfg(feature = "serde")]
extern crate serde;
I suppose. Or without the cfg line if you made the dependency non-optional.
1 Like
system
Closed
5
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.