Cannot use the `doc!` macro from the mongodb crate in the scope of a sub sub module

南笙酒味 提交于 2019-12-23 03:14:18

问题


I use following file structure:

├── src
│   ├── main.rs     // Macros from here
│   ├── models
│   │   ├── mod.rs  // Loads the user.rs file
│   │   └── user.rs // Should be visible here
├── Cargo.toml

My main.rs file imports the stuff like:

#[macro_use]
extern crate mongodb;

mod models;

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.
    }
}

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.


回答1:


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;


来源:https://stackoverflow.com/questions/45033782/cannot-use-the-doc-macro-from-the-mongodb-crate-in-the-scope-of-a-sub-sub-mod

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!