Closed ndelvalle closed 4 years ago
@ndelvalle thanks for opening the issue. Could be a few issues at play, but I would wager that the issue is coming from that fact that you are using wither=0.8.0
& wither_derive=0.6.1
. The two versions should match.
I would recommend that you update wither_derive to 0.8.0
as well, and report back. Remember to do a cargo update
after changing the version of wither_derive in your Cargo.toml.
If that is not the issue, then it is quite likely just an instability in the version of nightly you are using.
@thedodd thanks for the help, I updated the versions as you suggested, I am also using a stable version now and also did a cargo update
, but I keep having some isuess:
↵ 101 cargo run
Compiling rust-crud-api-poc v0.1.0 (/Users/ndelvalle/Projects/ndelvalle/rust-crud-api-poc)
warning: unused imports: `Client`, `Database`, `ThreadedDatabase`
--> src/main.rs:14:5
|
14 | Client, ThreadedClient,
| ^^^^^^
15 | db::{Database, ThreadedDatabase},
| ^^^^^^^^ ^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
error[E0053]: method `id` has an incompatible type for trait
--> src/main.rs:22:10
|
22 | #[derive(Model, Serialize, Deserialize)]
| ^^^^^ expected struct `wither::mongodb::oid::ObjectId`, found struct `mongodb::oid::ObjectId`
|
= note: expected type `fn(&User) -> std::option::Option<wither::mongodb::oid::ObjectId>`
found type `fn(&User) -> std::option::Option<mongodb::oid::ObjectId>`
note: Perhaps two different versions of crate `bson` are being used?
--> src/main.rs:22:10
|
22 | #[derive(Model, Serialize, Deserialize)]
| ^^^^^
error[E0053]: method `set_id` has an incompatible type for trait
--> src/main.rs:22:10
|
22 | #[derive(Model, Serialize, Deserialize)]
| ^^^^^ expected struct `wither::mongodb::oid::ObjectId`, found struct `mongodb::oid::ObjectId`
|
= note: expected type `fn(&mut User, wither::mongodb::oid::ObjectId)`
found type `fn(&mut User, mongodb::oid::ObjectId)`
note: Perhaps two different versions of crate `bson` are being used?
--> src/main.rs:22:10
|
22 | #[derive(Model, Serialize, Deserialize)]
| ^^^^^
error[E0053]: method `indexes` has an incompatible type for trait
--> src/main.rs:22:10
|
22 | #[derive(Model, Serialize, Deserialize)]
| ^^^^^ expected struct `wither::mongodb::coll::options::IndexModel`, found struct `mongodb::coll::options::IndexModel`
|
= note: expected type `fn() -> std::vec::Vec<wither::mongodb::coll::options::IndexModel>`
found type `fn() -> std::vec::Vec<mongodb::coll::options::IndexModel>`
note: Perhaps two different versions of crate `mongodb` are being used?
--> src/main.rs:22:10
|
22 | #[derive(Model, Serialize, Deserialize)]
| ^^^^^
error[E0308]: mismatched types
--> src/main.rs:37:13
|
37 | me.save(db.clone(), None);
| ^^^^^^^^^^ expected struct `wither::mongodb::db::DatabaseInner`, found struct `mongodb::db::DatabaseInner`
|
= note: expected type `std::sync::Arc<wither::mongodb::db::DatabaseInner>`
found type `std::sync::Arc<mongodb::db::DatabaseInner>`
note: Perhaps two different versions of crate `mongodb` are being used?
--> src/main.rs:37:13
|
37 | me.save(db.clone(), None);
| ^^^^^^^^^^
error[E0308]: mismatched types
--> src/main.rs:40:15
|
40 | me.update(db.clone(), None, doc!{"$set": doc!{"email": "new.email@example.com"}}, None).unwrap();
| ^^^^^^^^^^ expected struct `wither::mongodb::db::DatabaseInner`, found struct `mongodb::db::DatabaseInner`
|
= note: expected type `std::sync::Arc<wither::mongodb::db::DatabaseInner>`
found type `std::sync::Arc<mongodb::db::DatabaseInner>`
note: Perhaps two different versions of crate `mongodb` are being used?
--> src/main.rs:40:15
|
40 | me.update(db.clone(), None, doc!{"$set": doc!{"email": "new.email@example.com"}}, None).unwrap();
| ^^^^^^^^^^
error[E0308]: mismatched types
--> src/main.rs:40:33
|
40 | me.update(db.clone(), None, doc!{"$set": doc!{"email": "new.email@example.com"}}, None).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `wither::mongodb::ordered::OrderedDocument`, found struct `mongodb::ordered::OrderedDocument`
|
= note: expected type `wither::mongodb::ordered::OrderedDocument`
found type `mongodb::ordered::OrderedDocument`
note: Perhaps two different versions of crate `bson` are being used?
--> src/main.rs:40:33
|
40 | me.update(db.clone(), None, doc!{"$set": doc!{"email": "new.email@example.com"}}, None).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0308]: mismatched types
--> src/main.rs:43:32
|
43 | let all_users = User::find(db.clone(), None, None).unwrap();
| ^^^^^^^^^^ expected struct `wither::mongodb::db::DatabaseInner`, found struct `mongodb::db::DatabaseInner`
|
= note: expected type `std::sync::Arc<wither::mongodb::db::DatabaseInner>`
found type `std::sync::Arc<mongodb::db::DatabaseInner>`
note: Perhaps two different versions of crate `mongodb` are being used?
--> src/main.rs:43:32
|
43 | let all_users = User::find(db.clone(), None, None).unwrap();
| ^^^^^^^^^^
error: aborting due to 7 previous errors
Note that I am running the exact same example that you provided in the readme Env:
cargo --version
# cargo 1.38.0 (23ef9a4ef 2019-08-20)
rustup --version
# rustup 1.19.0 (2af131cf9 2019-09-08)
rustup show
# Default host: x86_64-apple-darwin
# rustup home: /Users/ndelvalle/.rustup
#
# installed toolchains
# --------------------
#
# stable-x86_64-apple-darwin (default)
# nightly-x86_64-apple-darwin
#
# active toolchain
# ----------------
#
# stable-x86_64-apple-darwin (default)
# rustc 1.38.0 (625451e37 2019-09-23)
Dependencies:
[dependencies]
serde = "1.0.101"
serde_derive = "1.0.101"
mongodb = "0.4.0"
wither = "0.8.0"
wither_derive = "0.8.0"
Thanks for the help! :)
Ah, I should have noticed this earlier, but at least part of the issue here is that wither uses mongodb 0.3
where your dependencies are specifying mongodb 0.4.0
, which is what is causing most of the issues above.
Is there a specific reason why you are using mongodb 0.4.0
? If not, just modify that version in your Cargo.toml ... or you can just remove it from your Cargo.toml and use the re-exported mongodb from the wither crate: https://docs.rs/wither/0.8.0/wither/#reexports
That re-export allows you to just use the mongodb crate directly from the wither crate, which means that you don't have to worry about version compatibility and such.
Awesome! It worked! Thanks @thedodd for the help 🙂
@ndelvalle awesome! Glad to hear it.
Hi, I am trying to run the example in the readme but this error comes up when cargo building the project. I'm using the latest versions:
Env:
Error:
I'm extremely newbie with rust, probably its an error on my end, but maybe you can point me in the right direction.