pub fn serve_connection<S, I, Bd>(&self, io: I, service: S) -> Connection<I, S, E>
    where
        S: HttpService<Body, ResBody = Bd>,
        S::Error: Into<Box<dyn StdError + Send + Sync>>,
        Bd: Payload,
        I: AsyncRead + AsyncWrite + Unpin,
        E: H2Exec<S::Future, Bd>,
    {
        let proto = match self.mode {
            ConnectionMode::H1Only | ConnectionMode::Fallback => {
                let mut conn = proto::Conn::new(io);
                if !self.keep_alive {
                    conn.disable_keep_alive();
                }
                if self.h1_half_close {
                    conn.set_allow_half_close();
                }
                if !self.h1_writev {
                    conn.set_write_strategy_flatten();
                }
                conn.set_flush_pipeline(self.pipeline_flush);
                if let Some(max) = self.max_buf_size {
                    conn.set_max_buf_size(max);
                }
                let sd = proto::h1::dispatch::Server::new(service);
                ProtoServer::H1(proto::h1::Dispatcher::new(sd, conn))
            }
            ConnectionMode::H2Only => {
                let rewind_io = Rewind::new(io);
                let h2 =
                    proto::h2::Server::new(rewind_io, service, &self.h2_builder, self.exec.clone());
                ProtoServer::H2(h2)
            }
        };

        Connection {
            conn: Some(proto),
            fallback: if self.mode == ConnectionMode::Fallback {
                Fallback::ToHttp2(self.h2_builder.clone(), self.exec.clone())
            } else {
                Fallback::Http1Only
            },
        }
    }
/// Bind a connection together with a [`Service`](crate::service::Service).
///
/// This returns a Future that must be polled in order for HTTP to be
/// driven on the connection.
///
/// # Example
///
/// ```
/// # use hyper::{Body, Request, Response};
/// # use hyper::service::Service;
/// # use hyper::server::conn::Http;
/// # use tokio::io::{AsyncRead, AsyncWrite};
/// # async fn run<I, S>(some_io: I, some_service: S)
/// # where
/// #     I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
/// #     S: Service<hyper::Request<Body>, Response=hyper::Response<Body>> + Send + 'static,
/// #     S::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
/// #     S::Future: Send,
/// # {
/// let http = Http::new();
/// let conn = http.serve_connection(some_io, some_service);
///
/// if let Err(e) = conn.await {
///     eprintln!("server connection error: {}", e);
/// }
/// # }
/// # fn main() {}
/// ```
Bind a connection together with a [`Service`](crate::service::Service).
This returns a Future that must be polled in order for HTTP to be
driven on the connection.
Bind a connection together with a [ ` Service ` ] ( crate :: service :: Service ) . This returns a Future that must be polled in order for HTTP to be driven on the connection .
pub fn serve_connection<S, I, Bd>(&self, io: I, service: S) -> Connection<I, S, E>
    where
        S: HttpService<Body, ResBody = Bd>,
        S::Error: Into<Box<dyn StdError + Send + Sync>>,
        Bd: Payload,
        I: AsyncRead + AsyncWrite + Unpin,
        E: H2Exec<S::Future, Bd>,
    {
        let proto = match self.mode {
            ConnectionMode::H1Only | ConnectionMode::Fallback => {
                let mut conn = proto::Conn::new(io);
                if !self.keep_alive {
                    conn.disable_keep_alive();
                }
                if self.h1_half_close {
                    conn.set_allow_half_close();
                }
                if !self.h1_writev {
                    conn.set_write_strategy_flatten();
                }
                conn.set_flush_pipeline(self.pipeline_flush);
                if let Some(max) = self.max_buf_size {
                    conn.set_max_buf_size(max);
                }
                let sd = proto::h1::dispatch::Server::new(service);
                ProtoServer::H1(proto::h1::Dispatcher::new(sd, conn))
            }
            ConnectionMode::H2Only => {
                let rewind_io = Rewind::new(io);
                let h2 =
                    proto::h2::Server::new(rewind_io, service, &self.h2_builder, self.exec.clone());
                ProtoServer::H2(h2)
            }
        };
        Connection {
            conn: Some(proto),
            fallback: if self.mode == ConnectionMode::Fallback {
                Fallback::ToHttp2(self.h2_builder.clone(), self.exec.clone())
            } else {
                Fallback::Http1Only
            },
        }
    }
pub fn serve_connection < S , I , Bd > ( & self , io : I , service : S ) -> Connection < I , S , E > where S : HttpService < Body , ResBody = Bd > , S :: Error : Into < Box < dyn StdError + Send + Sync > > , Bd : Payload , I : AsyncRead + AsyncWrite + Unpin , E : H2Exec < S :: Future , Bd > , { let proto = match self . mode { ConnectionMode :: H1Only | ConnectionMode :: Fallback => { let mut conn = proto :: Conn :: new ( io ) ; if ! self . keep_alive { conn . disable_keep_alive ( ) ; } if self . h1_half_close { conn . set_allow_half_close ( ) ; } if ! self . h1_writev { conn . set_write_strategy_flatten ( ) ; } conn . set_flush_pipeline ( self . pipeline_flush ) ; if let Some ( max ) = self . max_buf_size { conn . set_max_buf_size ( max ) ; } let sd = proto :: h1 :: dispatch :: Server :: new ( service ) ; ProtoServer :: H1 ( proto :: h1 :: Dispatcher :: new ( sd , conn ) ) } ConnectionMode :: H2Only => { let rewind_io = Rewind :: new ( io ) ; let h2 = proto :: h2 :: Server :: new ( rewind_io , service , & self . h2_builder , self . exec . clone ( ) ) ; ProtoServer :: H2 ( h2 ) } } ; Connection { conn : Some ( proto ) , fallback : if self . mode == ConnectionMode :: Fallback { Fallback :: ToHttp2 ( self . h2_builder . clone ( ) , self . exec . clone ( ) ) } else { Fallback :: Http1Only } , } }
Bind a connection together with a [`Service`](crate::service::Service).
Bind a connection together with a [ ` Service ` ] ( crate :: service :: Service ) .
&self
io
I
service
S
&self
io
I
service
S
example
None
use hyper::{body, request, response};
None
use hyper::service::service;
None
use hyper::server::conn::http;
None
use tokio::io::{asyncread, asyncwrite};
None
async fn run<i, s>(some_io: i, some_service: s)
None
where
None
i: asyncread + asyncwrite + unpin + send + 'static,
None
s: service<hyper::request<body>, response=hyper::response<body>> + send + 'static,
None
s::error: into<box<dyn std::error::error + send + sync>>,
None
s::future: send,
None
{
let http = Http::new();
let conn = http.serve_connection(some_io, some_service).

if let Err(e) = conn.await {
eprintln!("server connection error: {}", e);
}
let http = Http :: new () ; let conn = http . serve_connection ( some_io some_service ) . if let Err ( e ) = conn . await { eprintln! ( " server connection error : {} " e ) ; }
}
None
fn main() {}
None