Comments (10)
@somehowchris you just need to add the various dependencies described in this error log to your Cargo.toml.
Firstly, if you want to use tokio
as your runtime, then you need to add tokio to your dependencies. Regardless of which runtime you use (tokio
or async-std
) you will also need to add futures
as a dep as well. This is base line. Nothing I can do about these items on the Wither side.
However, this does bring up one item, which I had considered, but released the alpha in part to be able to solicit feedback on this issue. async_trait
on the other hand is fundamentally required, and so I'm considering just adding it as an export of Wither, and then referencing it via wither::async_trait
just to make it so that folks don't need to add it as a dep.
I think I'm going to add async_trait
as a pub export. That will make things a lot easier. Adding wither
, tokio
/async-std
and futures
to your dependencies is definitely something you will have to do though.
from wither.
@rumanbsl what we should probably do is request that the mongo team loosen their async-std requirement to “1” instead of a specific minor version like “1.5”.
from wither.
@somehowchris did adding those deps solve the problem?
from wither.
#54 should address this issue. The other items, you will have to add as deps on your own.
If you still have any problems, or need guidance on how to add those crates as dependencies to your project, just let me know.
from wither.
I am using async_std
instead of tokyo.
// main.rs
use futures::stream::StreamExt;
use serde::{Deserialize, Serialize};
use wither::bson::{doc, oid::ObjectId};
use wither::mongodb::Client;
use wither::prelude::*;
#[derive(Debug, Model, Serialize, Deserialize)]
#[model(index(keys = r#"doc!{"email": 1}"#, options = r#"doc!{"unique": true}"#))]
struct User {
/// The ID of the model.
#[serde(rename = "_id", skip_serializing_if = "Option::is_none")]
pub id: Option<ObjectId>,
/// The user's email address.
pub email: String,
}
#[async_std::main]
async fn main() -> Result<(), std::io::Error> {
let db = Client::with_uri_str("mongodb://localhost:27017/").await.unwrap().database("mydb");
let mut cursor = User::find(db.clone(), None, None).await.unwrap();
while let Some(user) = cursor.next().await {
println!("{:?}", user);
}
let mut app = tide::with_state(db);
app.at("/").get(|_| async { Ok("Hello, world!!!!") });
app.listen("127.0.0.1:8080").await?;
Ok(())
}
// cargo.toml
[package]
name = "graphql-tide-server"
version = "0.1.0"
authors = ["Ruman <[email protected]>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tide = "0.11.0"
async-std = { version = "1.6.2", features = ["attributes"] }
juniper = "0.14.2"
serde= { version = "1.0.114", features = ["derive"] }
serde_json = "1.0.56"
wither = "0.9.0-alpha.1"
wither_derive = "0.9.0-alpha.1"
validator = "0.10"
validator_derive = "0.10"
futures = "0.3.5"
giving Error
Running `target/debug/graphql-tide-server`
thread 'main' panicked at 'there is no timer running, must be called from the context of
Tokio runtime', /Users/<USER>/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.21/src/time/driver/handle.rs:24:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[Finished running. Exit status: 101]
from wither.
@rumanbsl looks like you just need to activate the async-std-runtime
for wither, and ensure the default features are deactivated.
As shown in the README, tokio is the default runtime:
As such, you should update your wither dependency declaration to simply be:
wither = { version = "0.9.0-alpha.1", default-features = false, features = ["async-std-runtime"] }
Also, the derive code is re-exported by wither, so you can actually remove the wither_derive = "0.9.0-alpha.1"
from your dependencies as well.
from wither.
Mongo is giving some error with async-std (switching async-std to 1.5 didn't help either)
failed to select a version for `async-std`.
... required by package `mongodb v1.0.0`
... which is depended on by `wither v0.9.0-alpha.1`
... which is depended on by `graphql-tide-server v0.1.0 (/Users/<USER>/Documents/dev/RUST_WORKSPACE/graphql-tide-server)`
versions that meet the requirements `~1.5.0` are: 1.5.0
all possible versions conflict with previously selected packages.
previously selected package `async-std v1.6.2`
... which is depended on by `async-h1 v2.0.2`
... which is depended on by `tide v0.11.0`
... which is depended on by `graphql-tide-server v0.1.0 (/Users/<USER>/Documents/dev/RUST_WORKSPACE/graphql-tide-server)`
failed to select a version for `async-std` which could resolve this conflict
I have resolved it by enabling tokio runtime in async_std for now, incase someone stumbled with the same problem.
async-std = { version = "1.6.2", features = ["attributes", "tokio02"] }
from wither.
So, to be sure, Wither itself does not directly depend on tokio or async-std. So the dependency which needs to be match is whatever version mongodb
itself depends upon. So, I know you mentioned that you tried to switch your dep to async-std 1.5
, but did you do a cargo update
after that? It could be that you updated it in your Cargo.toml, but that it wasn't updated in the lock file and therefore did not resolve the issue.
Either way, you absolutely should update your dependency on wither as I mentioned above:
wither = { version = "0.9.0-alpha.1", default-features = false, features = ["async-std-runtime"] }
I would recommend that you try that, and if you still run into issues, I'm still happy to help, I would just ask that you paste your Cargo.toml dependencies here so that I can try to pinpoint the issue.
from wither.
The problem is with different version of async-std
requirements for tide and mongo. Tide required ^1.6 while mongo requires 1.5. Either way, it has nothing to do with wither as you've mentioned.
from wither.
@thedodd It definitely make sense to pin only major version from mongo side, or for that matter any library
from wither.
Related Issues (20)
- thread 'main' panicked at 'there is no timer running, must be called from the context of a Tokio 0.2.x runtime' HOT 4
- Mongo Rust driver upgrade coming HOT 6
- wither::Migration extensions HOT 6
- How to run aggregations? HOT 3
- Document references / cross-collection population HOT 8
- Batch document creation? HOT 3
- How to Specify Enum Literals? HOT 4
- Nice way to collect a cursor? HOT 2
- Docs cleanup & updates
- Add `update_many` method HOT 3
- [Docs] How does projection work in Rust? HOT 1
- Using basic example HOT 11
- [Enhancement] add created at and updated at timestamps HOT 1
- Upgrade to mongo driver 2.0 HOT 1
- Re-introduce IndexModel from the official driver
- Partial updates and typed documents
- Non-ObjectId _id fields HOT 1
- Call to action HOT 6
- Wither not working with mongodb operating in async-std HOT 3
- Mongodb _id Serialized to Id
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wither.