Struct salvo_core::Server
source · [−]pub struct Server<L> { /* private fields */ }
Expand description
Server
Implementations
sourceimpl<L> Server<L> where
L: Listener,
L::Conn: Transport + Send + Unpin + 'static,
L::Error: Into<Box<dyn StdError + Send + Sync + 'static>>,
impl<L> Server<L> where
L: Listener,
L::Conn: Transport + Send + Unpin + 'static,
L::Error: Into<Box<dyn StdError + Send + Sync + 'static>>,
sourcepub async fn try_serve<S>(self, service: S) -> Result<(), Error> where
S: Into<Service>,
pub async fn try_serve<S>(self, service: S) -> Result<(), Error> where
S: Into<Service>,
Try to serve a service
sourcepub async fn serve_with_graceful_shutdown<S, G>(self, addr: S, signal: G) where
S: Into<Service>,
G: Future<Output = ()> + Send + 'static,
pub async fn serve_with_graceful_shutdown<S, G>(self, addr: S, signal: G) where
S: Into<Service>,
G: Future<Output = ()> + Send + 'static,
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("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("127.0.0.1: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> Send for Server<L> where
L: Send,
impl<L> Sync for Server<L> where
L: Sync,
impl<L> Unpin for Server<L> where
L: Unpin,
impl<L> UnwindSafe for Server<L> where
L: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more