#Wrapper for `hyper::Service`

3 messages · Page 1 of 1 (latest)

compact sail
#

Hey guys, I'm having major troubles with a wrapper for hyper. I want to create my own server that handles a custom Service trait. I've implemented this on top of hyper, but I get one specific error that I cannot get rid of:

error[E0271]: expected `{async block@acceptor.rs:63:13: 63:57}` to be a future that resolves to `Result<Response<_>, _>`, but it resolves to `impl Future<Output = Result<Response<Full<Bytes>>, ApiActionError>>`
   --> PROJECT/src/proto/http/acceptor.rs:72:62
    |
72  |                     .serve_connection(TokioIo::new(request), service)
    |                      ----------------                        ^^^^^^^ expected `Result<Response<_>, _>`, found future
    |                      |
    |                      required by a bound introduced by this call
    |
note: calling an async function returns a future
   --> PROJECT/src/proto/http/acceptor.rs:72:62
    |
72  |                     .serve_connection(TokioIo::new(request), service)
    |                                                              ^^^^^^^
    = note: required for `hyper::service::util::ServiceFn<{closure@acceptor.rs:61:50: 61:85}, hyper::body::Incoming>` to implement `hyper::service::Service<http::Request<hyper::body::Incoming>>`
note: required by a bound in `hyper_util::server::conn::auto::Builder::<E>::serve_connection`
   --> /root/.cargo/[...]/hyper-util-0.1.6/src/server/conn/auto.rs:131:39
    |
129 |     pub fn serve_connection<I, S, B>(&self, io: I, service: S) -> Connection<'_, I, S, E>
    |            ---------------- required by a bound in this associated function
130 |     where
131 |         S: Service<Request<Incoming>, Response = Response<B>>,
    |                                       ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Builder::<E>::serve_connection`
#

I don't know how to get rid of this. Some additional information:

  • the TcpAcceptor below is a wrapper around the tokio::new::TcpListener.
  • the hyper::ServiceFn and my own ServiceFunction implement each other.
  • the hyper::Request and hyper::Response can be converted to my custom Request and Response
  • the ApiActionError is not really relevant, but has some error types.