gotham-rs / gotham

A flexible web framework that promotes stability, safety, security and speed.

Home Page:https://gotham.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to build simple_async_handlers outside of the repo

JordanBoltonMN opened this issue · comments

I was having trouble implementing an async handler by following the repo's given example, so I:

  • Copy and pasted the simple_async_handlers into a separate directory
  • Set the "gotham" dependency to "0.4.0"
  • Set the "gotham_derive" to "0.4.0"
  • Ran cargo check and received the following:
PS C:\Git\simple_async_handlers> cargo check
    Checking gotham_examples_handlers_simple_async_handlers v0.0.0 (C:\Git\simple_async_handlers)
error[E0432]: unresolved import `gotham::hyper`
  --> src\main.rs:11:13
   |
11 | use gotham::hyper::StatusCode;
   |             ^^^^^ could not find `hyper` in `gotham`

error[E0433]: failed to resolve: could not find `hyper` in `{{root}}`
  --> src\main.rs:24:34
   |
24 | #[derive(Deserialize, StateData, StaticResponseExtender)]
   |                                  ^^^^^^^^^^^^^^^^^^^^^^ could not find `hyper` in `{{root}}`

error[E0308]: mismatched types
  --> src\main.rs:78:5
   |
65 |   fn sleep_handler(mut state: State) -> Pin<Box<HandlerFuture>> {
   |                                         ----------------------- expected `std::pin::Pin<std::boxed::Box<(dyn futures::future::Future<Error = (gotham::state::State, gotham::handler::error::HandlerError), Item = (gotham::state::State, http::response::Response<hyper::body::body::Body>)> + std::marker::Send + 'static)>>` because of return type
...
78 | /     sleep_future
79 | |         .map(move |data| {
80 | |             let res = create_response(&state, StatusCode::OK, mime::TEXT_PLAIN, data);
81 | |             println!("sleep for {} seconds once: finished", seconds);
82 | |             Ok((state, res))
83 | |         })
84 | |         .boxed()
   | |________________^ expected trait `futures::future::Future<Error = (gotham::state::State, gotham::handler::error::HandlerError), Item = (gotham::state::State, http::response::Response<hyper::body::body::Body>)> + std::marker::Send`, found trait `core::future::future::Future<Output = std::result::Result<(gotham::state::State, http::response::Response<hyper::body::body::Body>), _>> + std::marker::Send`
   |
   = note: expected struct `std::pin::Pin<std::boxed::Box<(dyn futures::future::Future<Error = (gotham::state::State, gotham::handler::error::HandlerError), Item = (gotham::state::State, http::response::Response<hyper::body::body::Body>)> + std::marker::Send + 'static)>>`  
              found struct `std::pin::Pin<std::boxed::Box<dyn core::future::future::Future<Output = std::result::Result<(gotham::state::State, http::response::Response<hyper::body::body::Body>), _>> + std::marker::Send>>`

error[E0308]: mismatched types
   --> src\main.rs:110:5
    |
92  |   fn loop_handler(mut state: State) -> Pin<Box<HandlerFuture>> {
    |                                        ----------------------- expected `std::pin::Pin<std::boxed::Box<(dyn futures::future::Future<Error = (gotham::state::State, gotham::handler::error::HandlerError), Item = (gotham::state::State, http::response::Response<hyper::body::body::Body>)> + std::marker::Send + 'static)>>` because of return type
...
110 | /     sleep_future
111 | |         .map(move |data| {
112 | |             let res = create_response(&state, StatusCode::OK, mime::TEXT_PLAIN, data);
113 | |             println!("sleep for one second {} times: finished", seconds);
114 | |             Ok((state, res))
115 | |         })
116 | |         .boxed()
    | |________________^ expected trait `futures::future::Future<Error = (gotham::state::State, gotham::handler::error::HandlerError), Item = (gotham::state::State, http::response::Response<hyper::body::body::Body>)> + std::marker::Send`, found trait `core::future::future::Future<Output = std::result::Result<(gotham::state::State, http::response::Response<hyper::body::body::Body>), _>> + std::marker::Send`
    |
    = note: expected struct `std::pin::Pin<std::boxed::Box<(dyn futures::future::Future<Error = (gotham::state::State, gotham::handler::error::HandlerError), Item = (gotham::state::State, http::response::Response<hyper::body::body::Body>)> + std::marker::Send + 'static)>>` 
               found struct `std::pin::Pin<std::boxed::Box<dyn core::future::future::Future<Output = std::result::Result<(gotham::state::State, http::response::Response<hyper::body::body::Body>), _>> + std::marker::Send>>`

error[E0277]: the trait bound `std::pin::Pin<std::boxed::Box<(dyn futures::future::Future<Error = (gotham::state::State, gotham::handler::error::HandlerError), Item = (gotham::state::State, http::response::Response<hyper::body::body::Body>)> + std::marker::Send + 'static)>>: gotham::handler::IntoHandlerFuture` is not satisfied
   --> src\main.rs:125:14
    |
125 |             .to(sleep_handler);
    |              ^^ the trait `gotham::handler::IntoHandlerFuture` is not implemented for `std::pin::Pin<std::boxed::Box<(dyn futures::future::Future<Error = (gotham::state::State, gotham::handler::error::HandlerError), Item = (gotham::state::State, http::response::Response<hyper::body::body::Body>)> + std::marker::Send + 'static)>>`
    |
    = note: required because of the requirements on the impl of `gotham::handler::Handler` for `fn(gotham::state::State) -> std::pin::Pin<std::boxed::Box<(dyn futures::future::Future<Error = (gotham::state::State, gotham::handler::error::HandlerError), Item = (gotham::state::State, http::response::Response<hyper::body::body::Body>)> + std::marker::Send + 'static)>> {sleep_handler}`

error[E0277]: the trait bound `std::pin::Pin<std::boxed::Box<(dyn futures::future::Future<Error = (gotham::state::State, gotham::handler::error::HandlerError), Item = (gotham::state::State, http::response::Response<hyper::body::body::Body>)> + std::marker::Send + 'static)>>: gotham::handler::IntoHandlerFuture` is not satisfied
   --> src\main.rs:129:14
    |
129 |             .to(loop_handler);
    |              ^^ the trait `gotham::handler::IntoHandlerFuture` is not implemented for `std::pin::Pin<std::boxed::Box<(dyn futures::future::Future<Error = (gotham::state::State, gotham::handler::error::HandlerError), Item = (gotham::state::State, http::response::Response<hyper::body::body::Body>)> + std::marker::Send + 'static)>>`
    |
    = note: required because of the requirements on the impl of `gotham::handler::Handler` for `fn(gotham::state::State) -> std::pin::Pin<std::boxed::Box<(dyn futures::future::Future<Error = (gotham::state::State, gotham::handler::error::HandlerError), Item = (gotham::state::State, http::response::Response<hyper::body::body::Body>)> + std::marker::Send + 'static)>> {loop_handler}`

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0277, E0308, E0432, E0433.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `gotham_examples_handlers_simple_async_handlers`.

To learn more, run the command again with --verbose.
PS C:\Git\simple_async_handlers> 

It looks like there's two errors. The first being that it's expecting hyper to be re-exported in gotham. The second I /think/ it's expecting the future implementation futures::future::Future but got a different future implementation.

I'm guessing this comes down to a simple version mismatch, though I don't know how to resolve it. In Cargo.toml I was assuming it pulls in the local project, so I tried to update gotham's version but it looks like 0.4.0 is currently the latest. here is my repro which is just the main.rs and Cargo files.

Let me know if there's anything else I can do to help investigate the issue.

C:\Users\XXX>cargo -V
cargo 1.41.0 (626f0f40e 2019-12-03)

C:\Users\XXX>rustup -V
rustup 1.21.1 (7832b2ebe 2019-12-20)

C:\Users\XXX>rustup default
stable-x86_64-pc-windows-msvc (default)

Hi @JordanBoltonMN - check that you use example code from the 0.4.0 tag - or use gotham from github master in your dependencies, as things in master have changed to support rust async since the last release.

That was the issue. Would you expect less work / issues if I target master, or would targeting a stable release (0.4.0) cause less trouble than later updating the async code?

Either way, this can be marked as closed.