thedodd / wither

An ODM for MongoDB built on the official MongoDB Rust driver.
https://docs.rs/wither
Other
328 stars 40 forks source link

Cannot find derive macro `Model` in this scope #64

Closed adamfriedland closed 4 years ago

adamfriedland commented 4 years ago

I seem to be having an issue inserting this derived trait into my scope. I'm using the standard example on the read me available as well. I'm using the latest stable build of Rust currently which at this time is 1.47.0. I'm still rather green to the language so apologies in advance if this is some silly issue. image

thedodd commented 4 years ago

Hey @adamfriedland no problem. You will notice here (https://github.com/thedodd/wither/blob/master/wither/examples/readme.rs) that the example code actually uses the following import: use wither::{prelude::*, Result};, so in your code sample above, I would recommend that you replace your use wither::Model; with user wither::prelude::*;.

What is happening here is that you are actually importing the wither::Model trait, not the derive macro. They are both named the same, however the prelude module exposes them both.

The other option, depending on your preference, would be to modify your derive to be #[derive(Debug, wither::Model, ...)] because Rust will know that you are referring to the derive-macro in that case.

Cheers

adamfriedland commented 4 years ago

Yes, I took at look at the references and saw what you meant. There appears to be reference ambiguity that the compiler doesn't know how to resolve correctly. Prior to this, I did end up just opting into the alpha build and that actually resolved quite a few of the issues I had, even if it sacrifices indexing in the interim. Keep up the good work @thedodd. We need a good strongly typed mongodb implementation.

thedodd commented 4 years ago

@adamfriedland awesome! Glad to hear it. Thanks for the encouragement :). Definitely a lot going on, but hopefully we'll be able to get the index PR landed soon so we can cut the official 0.9 release.