不能在子子模块的范围内使用来自 mongodb crate 的 `doc!` 宏 [英] Cannot use the `doc!` macro from the mongodb crate in the scope of a sub sub module
本文介绍了不能在子子模块的范围内使用来自 mongodb crate 的 `doc!` 宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下文件结构:
├── src
│ ├── main.rs // Macros from here
│ ├── models
│ │ ├── mod.rs // Loads the user.rs file
│ │ └── user.rs // Should be visible here
├── Cargo.toml
我的 main.rs
文件导入如下内容:
My main.rs
file imports the stuff like:
#[macro_use]
extern crate mongodb;
mod models;
我的 user.rs
文件看起来像:
My user.rs
file looks like:
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;
之类的东西中,但没有任何效果.
How can I use my doc!
macro in the user.rs
file? I also tried to add #[macro_use]
to the stuff like mod models;
, but nothing worked.
推荐答案
mongodb crate (version 0.3.1) 没有这样的宏.bson crate(0.9.0 版),一个依赖项mongodb,确实如此.您需要声明并从那里导入:
The mongodb crate (version 0.3.1) has no such macro. The bson crate (version 0.9.0), a dependency of mongodb, does. You need to declare that and import from there:
#[macro_use]
extern crate bson;
extern crate mongodb;
这篇关于不能在子子模块的范围内使用来自 mongodb crate 的 `doc!` 宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文