shuttle_tide/
lib.rs

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