Struct salvo::prelude::Server [−][src]
pub struct Server<L> { /* fields omitted */ }
Expand description
Server
Implementations
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(());
}
Auto Trait Implementations
impl<L> RefUnwindSafe for Server<L> where
L: RefUnwindSafe,
impl<L> UnwindSafe for Server<L> where
L: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
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