Struct salvo::Server[][src]

pub struct Server<L> { /* fields omitted */ }
Expand description

Server

Implementations

Create new Server.

Serve a service

Try to serve a service

Serve with graceful shutdown signal.

Example
use salvo_core::prelude::*;
use salvo_macros::fn_handler;
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(TcpListener::bind(([0, 0, 0, 0], 7878))).serve_with_graceful_shutdown(router, async {
        rx.await.ok();
    });

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

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

Serve with graceful shutdown signal.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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