-
Notifications
You must be signed in to change notification settings - Fork 322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A problem with switching from 0.3 to 0.4 #370
Comments
@importcjj o/ thanks for reporting! At a glance I'm unsure what's causing this failure. Just to verify: which Rust version are you using? Did you only update the Tide version, or also Rust versions? I just wrote a quick example to verify that we can indeed read from the global state: use async_std::io;
use async_std::task;
/// Shared application state.
#[derive(Debug)]
struct State {
name: String,
}
fn main() -> io::Result<()> {
task::block_on(async {
let mut app = tide::with_state(State { name: "nori".to_string() });
app.at("/submit").post(|req: tide::Request<State>| {
async move {
let name = &req.state().name;
tide::Response::new(200).body_string(name.to_string())
}
});
app.listen("127.0.0.1:8080").await?;
Ok(())
})
} I'd be happy to help you debug further if you could share a repro. I'm sorry this is happening, but thanks again for reporting! |
My Rust version
Here is a simple demo. https://github.com/importcjj/tide-demo/blob/master/src/main.rs |
@importcjj I updated to a recent nightly version, and the diagnostics were super helpful! Solved the problem, and included the code. The short version is: I'm not exactly sure what caused this to trip up in a recent Tide version, but the problem is easily sidestepped. It seems somewhat similar to the lifetime inference changes that happened as part of Happy this seems to have been resolved though. Let me know how this works out for you, and then I think we should be okay to close this. Thanks! ScreenshotCodeuse async_std::io;
use async_std::task;
use mobc::{ConnectionManager, runtime::DefaultExecutor, Pool, AnyFuture};
struct FooManager;
struct FooConnection;
impl FooConnection {
async fn query(&self) -> String {
"nori".to_string()
}
}
impl ConnectionManager for FooManager {
type Connection = FooConnection;
type Error = std::io::Error;
type Executor = DefaultExecutor;
fn get_executor(&self) -> Self::Executor {
DefaultExecutor::current()
}
fn connect(&self) -> AnyFuture<Self::Connection, Self::Error> {
Box::pin(futures::future::ok(FooConnection))
}
fn is_valid(&self, conn: Self::Connection) -> AnyFuture<Self::Connection, Self::Error> {
Box::pin(futures::future::ok(conn))
}
fn has_broken(&self, conn: &mut Option<Self::Connection>) -> bool {
false
}
}
/// Shared application state.
struct State {
pool: Pool<FooManager>
}
fn main() -> io::Result<()> {
task::block_on(async {
let pool = Pool::new(FooManager).await.unwrap();
let mut app = tide::with_state(State { pool });
app.at("/submit").post(|req: tide::Request<State>| {
async move {
let pool = &req.state().pool;
let conn = pool.get().await.unwrap();
let name = conn.query().await;
tide::Response::new(200).body_string("hello".to_string())
}
});
app.listen("127.0.0.1:8080").await?;
Ok(())
})
} |
@yoshuawuyts I know you said the ping wasn't a bug report, but I see that even though that change will be obvious to anyone reading the output with a moderate level of experience with Rust, that hint is not in the output and can be beyond the level of understanding of someone just starting out (or a decaffeinated experienced dev). That makes me think we might want to add a |
@estebank done! |
Thank you! |
@importcjj is the new error understandable to you? If not, please join the thread at the linked rust ticket. |
@estebank The new error message is clear enough, but I'm just confused about the tide state() API. @yoshuawuyts Why not just use |
@importcjj providing public field access, unless directly modifiable as part of a constructor, is somewhat of an anti-pattern. Not too thrilled about type inference having a bad time here, but my hopes is that as work on async/await continues, inference will eventually catch up. |
I use mobc as my connection pool.
Here is the HelloWorld demo.
It's ok in tide 0.3, but it complied failed in tide 0.4
Here is the error message, my pool is
sync + send + 'static
, I don't know which part isunsync
The text was updated successfully, but these errors were encountered: