我使用以下文件结构:
├── src
│ ├── main.rs // Macros from here
│ ├── models
│ │ ├── mod.rs // Loads the user.rs file
│ │ └── user.rs // Should be visible here
├── Cargo.toml
我的 main.rs
文件导入如下内容:
#[macro_use]
extern crate mongodb;
mod models;
我的 user.rs
文件如下所示:
pub struct User {
username: String,
password: String,
}
impl User {
fn create_doc() {
// Some code, but doc! from crate mongodb is not in this scope.
}
}
如何在 user.rs
文件中使用我的 doc!
宏?我还尝试将 #[macro_use]
添加到 mod models;
之类的内容中,但没有任何效果。
最佳答案
mongodb crate(版本 0.3.1)has no such macro . bson crate (version 0.9.0) ,mongodb 的依赖项,确实如此。您需要声明并从那里导入:
#[macro_use]
extern crate bson;
extern crate mongodb;
关于rust - 无法在子模块范围内使用 mongodb crate 中的 `doc!` 宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45033782/