[][src]Struct salvo::Server

pub struct Server {
    pub router: Arc<Router>,
    pub catchers: Arc<Vec<Box<dyn Catcher + 'static, Global>, Global>>,
    pub allowed_media_types: Arc<Vec<Mime, Global>>,
}

Fields

router: Arc<Router>catchers: Arc<Vec<Box<dyn Catcher + 'static, Global>, Global>>allowed_media_types: Arc<Vec<Mime, Global>>

Implementations

impl Server[src]

pub fn new(router: Router) -> Server[src]

pub async fn bind(self, addr: impl Into<SocketAddr> + 'static)[src]

Bind to a socket address, returning a Future that can be executed on any runtime.

Panics

Panics if we are unable to bind to the provided address.

pub async fn try_bind(
    self,
    addr: impl Into<SocketAddr>
) -> Result<SocketAddr, Error>
[src]

Bind to a socket address, returning a Future that can be executed on any runtime.

In case we are unable to bind to the specified address, resolves to an error and logs the reason.

pub async fn bind_with_graceful_shutdown(
    self,
    addr: impl Into<SocketAddr> + 'static,
    signal: impl Send + Future<Output = ()> + 'static
)
[src]

Create a server with graceful shutdown signal.

When the signal completes, the server will start the graceful shutdown process.

Returns the bound address and a Future that can be executed on any runtime.

Example

use salvo_core::prelude::*;
use tokio::sync::oneshot;

#[fn_handler]
async fn hello_world(res: &mut Response) {
    res.render_plain_text("Hello World!");
}
 
#[tokio::main]
async fn main() {
    let (tx, rx) = oneshot::channel();
    let router = Router::new().get(hello_world);
    let server = Server::new(router).bind_with_graceful_shutdown(([0, 0, 0, 0], 3131), async {
            rx.await.ok();
    });

    // Spawn the server into a runtime
    tokio::task::spawn(server);

    // Later, start the shutdown...
    let _ = tx.send(());
}

pub async fn try_bind_with_graceful_shutdown(
    self,
    addr: impl Into<SocketAddr> + 'static,
    signal: impl Send + Future<Output = ()> + 'static
) -> Result<SocketAddr, Error>
[src]

Create a server with graceful shutdown signal.

When the signal completes, the server will start the graceful shutdown process.

pub async fn bind_incoming<I>(self, incoming: I) where
    I: TryStream + Send,
    <I as TryStream>::Ok: AsyncRead,
    <I as TryStream>::Ok: AsyncWrite,
    <I as TryStream>::Ok: Send,
    <I as TryStream>::Ok: 'static,
    <I as TryStream>::Ok: Unpin,
    <I as TryStream>::Error: Into<Box<dyn Error + 'static + Send + Sync, Global>>, 
[src]

Bind to a stream, returning a Future that can be executed on any runtime.

Panics

Panics if we are unable to bind to the provided address.

pub async fn try_bind_incoming<I>(self, incoming: I) -> Result<(), Error> where
    I: TryStream + Send,
    <I as TryStream>::Ok: AsyncRead,
    <I as TryStream>::Ok: AsyncWrite,
    <I as TryStream>::Ok: Send,
    <I as TryStream>::Ok: 'static,
    <I as TryStream>::Ok: Unpin,
    <I as TryStream>::Error: Into<Box<dyn Error + 'static + Send + Sync, Global>>, 
[src]

Run this Server forever on the current thread with a specific stream of incoming connections.

This can be used for Unix Domain Sockets, or TLS, etc.

pub async fn bind_incoming_with_graceful_shutdown<I>(
    self,
    incoming: I,
    signal: impl Send + Future<Output = ()> + 'static
) where
    I: TryStream + Send,
    <I as TryStream>::Ok: AsyncRead,
    <I as TryStream>::Ok: AsyncWrite,
    <I as TryStream>::Ok: Send,
    <I as TryStream>::Ok: 'static,
    <I as TryStream>::Ok: Unpin,
    <I as TryStream>::Error: Into<Box<dyn Error + 'static + Send + Sync, Global>>, 
[src]

pub async fn try_bind_incoming_with_graceful_shutdown<I>(
    self,
    incoming: I,
    signal: impl Send + Future<Output = ()> + 'static
) -> Result<(), Error> where
    I: TryStream + Send,
    <I as TryStream>::Ok: AsyncRead,
    <I as TryStream>::Ok: AsyncWrite,
    <I as TryStream>::Ok: Send,
    <I as TryStream>::Ok: 'static,
    <I as TryStream>::Ok: Unpin,
    <I as TryStream>::Error: Into<Box<dyn Error + 'static + Send + Sync, Global>>, 
[src]

Setup this Server with a specific stream of incoming connections and a signal to initiate graceful shutdown.

This can be used for Unix Domain Sockets, or TLS, etc.

When the signal completes, the server will start the graceful shutdown process.

Returns a Future that can be executed on any runtime.

pub fn tls(self) -> TlsServer[src]

Configure a server to use TLS.

This function requires the "tls" feature.

Trait Implementations

impl<T> Service<T> for Server[src]

type Response = HyperHandler

Responses given by the service.

type Error = Error

Errors produced by the service.

type Future = Ready<Result<<Server as Service<T>>::Response, <Server as Service<T>>::Error>>

The future response value.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> WithSubscriber for T[src]