Struct hyper::server::Server [−][src]
pub struct Server<I, S, E = Exec> { /* fields omitted */ }
Expand description
A listening HTTP server that accepts connections in both HTTP1 and HTTP2 by default.
Server
is a Future
mapping a bound listener with a set of service
handlers. It is built using the Builder
, and the future
completes when the server has been shutdown. It should be run by an
Executor
.
Implementations
Tries to bind to the provided address, and returns a Builder
.
Create a new instance from a std::net::TcpListener
instance.
Returns the local address that this server is bound to.
impl<I, IO, IE, S, E, B> Server<I, S, E> where
I: Accept<Conn = IO, Error = IE>,
IE: Into<Box<dyn StdError + Send + Sync>>,
IO: AsyncRead + AsyncWrite + Unpin + Send + 'static,
S: MakeServiceRef<IO, Body, ResBody = B>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
B: HttpBody + 'static,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
E: ConnStreamExec<<S::Service as HttpService<Body>>::Future, B>,
E: NewSvcExec<IO, S::Future, S::Service, E, GracefulWatcher>,
impl<I, IO, IE, S, E, B> Server<I, S, E> where
I: Accept<Conn = IO, Error = IE>,
IE: Into<Box<dyn StdError + Send + Sync>>,
IO: AsyncRead + AsyncWrite + Unpin + Send + 'static,
S: MakeServiceRef<IO, Body, ResBody = B>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
B: HttpBody + 'static,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
E: ConnStreamExec<<S::Service as HttpService<Body>>::Future, B>,
E: NewSvcExec<IO, S::Future, S::Service, E, GracefulWatcher>,
pub fn with_graceful_shutdown<F>(self, signal: F) -> Graceful<I, S, F, E> where
F: Future<Output = ()>,
pub fn with_graceful_shutdown<F>(self, signal: F) -> Graceful<I, S, F, E> where
F: Future<Output = ()>,
Prepares a server to handle graceful shutdown when the provided future completes.
Example
// Make a server from the previous examples...
let server = Server::bind(&([127, 0, 0, 1], 3000).into())
.serve(make_service);
// Prepare some signal for when the server should start shutting down...
let (tx, rx) = tokio::sync::oneshot::channel::<()>();
let graceful = server
.with_graceful_shutdown(async {
rx.await.ok();
});
// Await the `server` receiving the signal...
if let Err(e) = graceful.await {
eprintln!("server error: {}", e);
}
// And later, trigger the signal by calling `tx.send(())`.
let _ = tx.send(());
Trait Implementations
impl<I, IO, IE, S, B, E> Future for Server<I, S, E> where
I: Accept<Conn = IO, Error = IE>,
IE: Into<Box<dyn StdError + Send + Sync>>,
IO: AsyncRead + AsyncWrite + Unpin + Send + 'static,
S: MakeServiceRef<IO, Body, ResBody = B>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
B: HttpBody + 'static,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
E: ConnStreamExec<<S::Service as HttpService<Body>>::Future, B>,
E: NewSvcExec<IO, S::Future, S::Service, E, NoopWatcher>,
impl<I, IO, IE, S, B, E> Future for Server<I, S, E> where
I: Accept<Conn = IO, Error = IE>,
IE: Into<Box<dyn StdError + Send + Sync>>,
IO: AsyncRead + AsyncWrite + Unpin + Send + 'static,
S: MakeServiceRef<IO, Body, ResBody = B>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
B: HttpBody + 'static,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
E: ConnStreamExec<<S::Service as HttpService<Body>>::Future, B>,
E: NewSvcExec<IO, S::Future, S::Service, E, NoopWatcher>,
Auto Trait Implementations
impl<I, S, E> RefUnwindSafe for Server<I, S, E> where
E: RefUnwindSafe,
I: RefUnwindSafe,
S: RefUnwindSafe,
impl<I, S, E> UnwindSafe for Server<I, S, E> where
E: UnwindSafe,
I: UnwindSafe,
S: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Map this future’s output to a different type, returning a new future of the resulting type. Read more
Map this future’s output to a different type, returning a new future of the resulting type. Read more
Chain on a computation for when a future finished, passing the result of
the future to the provided closure f
. Read more
Wrap this future in an Either
future, making it the left-hand variant
of that Either
. Read more
Wrap this future in an Either
future, making it the right-hand variant
of that Either
. Read more
Convert this future into a single element stream. Read more
Flatten the execution of this future when the output of this future is itself another future. Read more
Flatten the execution of this future when the successful result of this future is a stream. Read more
Fuse a future such that poll
will never again be called once it has
completed. This method can be used to turn any Future
into a
FusedFuture
. Read more
Do something with the output of a future before passing it on. Read more
Catches unwinding panics while polling the future. Read more
Create a cloneable handle to this future where all handles will resolve to the same result. Read more
Wrap the future in a Box, pinning it. Read more
Wrap the future in a Box, pinning it. Read more
Turns a Future<Output = T>
into a
TryFuture<Ok = T, Error = ()
>. Read more
Turns a Future<Output = T>
into a
TryFuture<Ok = T, Error = Never
>. Read more
A convenience for calling Future::poll
on Unpin
future types.
Evaluates and consumes the future, returning the resulting output if
the future is ready after the first call to Future::poll
. Read more
into_future
)The output that the future will produce on completion.
type Future = F
type Future = F
into_future
)Which kind of future are we turning this into?
into_future
)Creates a future from a value.
Maps this future’s success value to a different value. Read more
Maps this future’s success value to a different value, and permits for error handling resulting in the same type. Read more
Maps this future’s error value to a different value. Read more
Executes another future after this one resolves successfully. The success value is passed to a closure to create this subsequent future. Read more
Executes another future if this one resolves to an error. The error value is passed to a closure to create this subsequent future. Read more
Do something with the success value of a future before passing it on. Read more
Do something with the error value of a future before passing it on. Read more
Flatten the execution of this future when the successful result of this future is another future. Read more
Flatten the execution of this future when the successful result of this future is a stream. Read more
fn unwrap_or_else<F>(self, f: F) -> UnwrapOrElse<Self, F> where
F: FnOnce(Self::Error) -> Self::Ok,
fn unwrap_or_else<F>(self, f: F) -> UnwrapOrElse<Self, F> where
F: FnOnce(Self::Error) -> Self::Ok,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more