via

Struct Server

source
pub struct Server<State> { /* private fields */ }
Expand description

Serve an App over HTTP or HTTPS.

Implementations§

source§

impl<State> Server<State>
where State: Send + Sync + 'static,

source

pub fn new(app: App<State>) -> Self

Creates a new server for the provided app.

source

pub fn listen<A: ToSocketAddrs>( self, address: A, ) -> impl Future<Output = Result<(), Error>>

Starts the server and listens for incoming connections at the provided address. Returns a future that resolves when the server is shutdown.

§Errors

If the server fails to bind to the provided address or is unable to finish serving all of the inflight connections within the specified shutdown timeout when a shutdown signal is received.

source

pub fn shutdown_timeout(self, timeout: u64) -> Self

Set the amount of time in seconds that the server will wait for inflight connections to complete before shutting down. The default value is 30 seconds.

source

pub fn max_connections(self, n: usize) -> Self

Sets the maximum number of concurrent connections that the server can accept. The default value is 256.

We suggest not setting this value unless you know what you are doing and have a good reason to do so. If you are unsure, it is best to leave this value at the default and scale horizontally.

If you do set this value, we suggest doing so by profiling the stack size of your application when it’s under load and incrementally increasing this value until you find a balance between performance and worry-free programming. In other words, the closer this value is to the limit based on your application’s stack consumption and the stack size of your server, the more careful you will need to be when allocating values on the stack (i.e dereferencing a heap pointer). Otherwise, you may encounter a stack overflow. In addition to the stack size, you should also consider not setting this value higher than the number of available file descriptors (or ulimit -n) on POSIX systems.

Auto Trait Implementations§

§

impl<State> Freeze for Server<State>

§

impl<State> !RefUnwindSafe for Server<State>

§

impl<State> Send for Server<State>
where State: Sync + Send,

§

impl<State> Sync for Server<State>
where State: Sync + Send,

§

impl<State> Unpin for Server<State>

§

impl<State> !UnwindSafe for Server<State>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.