shuttle_salvo/
lib.rs

1#![doc = include_str!("../README.md")]
2use salvo::Listener;
3use shuttle_runtime::Error;
4use std::net::SocketAddr;
5
6pub use salvo;
7
8/// A wrapper type for [salvo::Router] so we can implement [shuttle_runtime::Service] for it.
9pub struct SalvoService(pub salvo::Router);
10
11#[shuttle_runtime::async_trait]
12impl shuttle_runtime::Service for SalvoService {
13    /// Takes the router that is returned by the user in their [shuttle_runtime::main] function
14    /// and binds to an address passed in by shuttle.
15    async fn bind(mut self, addr: SocketAddr) -> Result<(), Error> {
16        let listener = salvo::conn::TcpListener::new(addr).bind().await;
17
18        salvo::Server::new(listener).serve(self.0).await;
19
20        Ok(())
21    }
22}
23
24impl From<salvo::Router> for SalvoService {
25    fn from(router: salvo::Router) -> Self {
26        Self(router)
27    }
28}
29
30#[doc = include_str!("../README.md")]
31pub type ShuttleSalvo = Result<SalvoService, Error>;