Skip to content

A problem with switching from 0.3 to 0.4 #370

Closed
@importcjj

Description

@importcjj

I use mobc as my connection pool.
Here is the HelloWorld demo.

pub struct Global {
    redis: Pool<RedisConnectionManager<DefaultExecutor>>,
    postgres: Pool<PostgresConnectionManager<NoTls, DefaultExecutor>>,
}

async fn helloworld(cx: Request<Global>) -> String { 
    match cx.state().redis.get().await {
        Ok(_) => "Rust rua!!!".to_string(),
        Err(_e) => "SERVER ERROR".to_string(),
    }
}

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 is unsync

error[E0277]: `(dyn futures_io::if_std::AsyncBufRead + std::marker::Send + 'static)` cannot be shared between threads safely
  --> api/src/main.rs:84:17
   |
84 |     app.at("/").get(helloworld);
   |                 ^^^ `(dyn futures_io::if_std::AsyncBufRead + std::marker::Send + 'static)` cannot be shared between threads safely
   |
   = help: the trait `std::marker::Sync` is not implemented for `(dyn futures_io::if_std::AsyncBufRead + std::marker::Send + 'static)`
   = note: required because of the requirements on the impl of `std::marker::Sync` for `std::ptr::Unique<(dyn futures_io::if_std::AsyncBufRead + std::marker::Send + 'static)>`
   = note: required because it appears within the type `std::boxed::Box<(dyn futures_io::if_std::AsyncBufRead + std::marker::Send + 'static)>`
   = note: required because it appears within the type `std::pin::Pin<std::boxed::Box<(dyn futures_io::if_std::AsyncBufRead + std::marker::Send + 'static)>>`
   = note: required because it appears within the type `http_service::Body`
   = note: required because it appears within the type `http::request::Request<http_service::Body>`
   = note: required because it appears within the type `tide::request::Request<Global>`
   = note: required because of the requirements on the impl of `std::marker::Send` for `&tide::request::Request<Global>`
   = note: required because it appears within the type `for<'r, 's, 't0, 't1> {tide::request::Request<Global>, &'r tide::request::Request<Global>, Global, &'s Global, &'t0 mobc::Pool<mobc_postgres::PostgresConnectionManager<tokio_postgres::tls::NoTls, mobc::runtime::DefaultExecutor>>, mobc::Pool<mobc_postgres::PostgresConnectionManager<tokio_postgres::tls::NoTls, mobc::runtime::DefaultExecutor>>, impl std::future::Future, ()}`
   = note: required because it appears within the type `[static generator@api/src/main.rs:34:52: 43:2 cx:tide::request::Request<Global> for<'r, 's, 't0, 't1> {tide::request::Request<Global>, &'r tide::request::Request<Global>, Global, &'s Global, &'t0 mobc::Pool<mobc_postgres::PostgresConnectionManager<tokio_postgres::tls::NoTls, mobc::runtime::DefaultExecutor>>, mobc::Pool<mobc_postgres::PostgresConnectionManager<tokio_postgres::tls::NoTls, mobc::runtime::DefaultExecutor>>, impl std::future::Future, ()}]`
   = note: required because it appears within the type `std::future::GenFuture<[static generator@api/src/main.rs:34:52: 43:2 cx:tide::request::Request<Global> for<'r, 's, 't0, 't1> {tide::request::Request<Global>, &'r tide::request::Request<Global>, Global, &'s Global, &'t0 mobc::Pool<mobc_postgres::PostgresConnectionManager<tokio_postgres::tls::NoTls, mobc::runtime::DefaultExecutor>>, mobc::Pool<mobc_postgres::PostgresConnectionManager<tokio_postgres::tls::NoTls, mobc::runtime::DefaultExecutor>>, impl std::future::Future, ()}]>`
   = note: required because it appears within the type `impl std::future::Future`
   = note: required because it appears within the type `impl std::future::Future`
   = note: required because of the requirements on the impl of `tide::endpoint::Endpoint<Global>` for `fn(tide::request::Request<Global>) -> impl std::future::Future {helloworld}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions