shuttle_thruster/
lib.rs

1#![doc = include_str!("../README.md")]
2use shuttle_runtime::Error;
3use std::net::SocketAddr;
4
5pub use thruster;
6
7/// A wrapper type for [thruster::ThrusterServer] so we can implement [shuttle_runtime::Service] for it.
8pub struct ThrusterService<T>(pub T);
9
10#[shuttle_runtime::async_trait]
11impl<T> shuttle_runtime::Service for ThrusterService<T>
12where
13    T: thruster::ThrusterServer + Send + 'static,
14{
15    /// Takes the server 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.build(&addr.ip().to_string(), addr.port()).await;
19
20        Ok(())
21    }
22}
23
24impl<T> From<T> for ThrusterService<T>
25where
26    T: thruster::ThrusterServer + Send + 'static,
27{
28    fn from(router: T) -> Self {
29        Self(router)
30    }
31}
32
33#[doc = include_str!("../README.md")]
34pub type ShuttleThruster<T> = Result<ThrusterService<T>, Error>;