#![doc = include_str!("../README.md")]
use shuttle_runtime::{CustomError, Error};
use std::net::SocketAddr;
#[cfg(feature = "axum")]
use axum::Router;
#[cfg(feature = "axum-0-6")]
use axum_0_6::Router;
pub struct AxumService(pub Router);
#[shuttle_runtime::async_trait]
impl shuttle_runtime::Service for AxumService {
async fn bind(mut self, addr: SocketAddr) -> Result<(), Error> {
#[cfg(feature = "axum")]
axum::serve(
shuttle_runtime::tokio::net::TcpListener::bind(addr)
.await
.map_err(CustomError::new)?,
self.0,
)
.await
.map_err(CustomError::new)?;
#[cfg(feature = "axum-0-6")]
axum_0_6::Server::bind(&addr)
.serve(self.0.into_make_service())
.await
.map_err(CustomError::new)?;
Ok(())
}
}
impl From<Router> for AxumService {
fn from(router: Router) -> Self {
Self(router)
}
}
#[doc = include_str!("../README.md")]
pub type ShuttleAxum = Result<AxumService, Error>;