1#![doc = include_str!("../README.md")]
2use shuttle_runtime::Error;
3use std::net::SocketAddr;
4use std::ops::Deref;
5
6pub use warp;
7
8pub struct WarpService<T>(pub T);
10
11#[shuttle_runtime::async_trait]
12impl<T> shuttle_runtime::Service for WarpService<T>
13where
14 T: Send + Sync + Clone + 'static + warp::Filter,
15 T::Extract: warp::reply::Reply,
16{
17 async fn bind(mut self, addr: SocketAddr) -> Result<(), Error> {
20 warp::serve((*self).clone()).run(addr).await;
21 Ok(())
22 }
23}
24
25impl<T> From<T> for WarpService<T>
26where
27 T: Send + Sync + Clone + 'static + warp::Filter,
28 T::Extract: warp::reply::Reply,
29{
30 fn from(router: T) -> Self {
31 Self(router)
32 }
33}
34
35impl<T> Deref for WarpService<T> {
36 type Target = T;
37
38 fn deref(&self) -> &Self::Target {
39 &self.0
40 }
41}
42
43#[doc = include_str!("../README.md")]
44pub type ShuttleWarp<T> = Result<WarpService<warp::filters::BoxedFilter<T>>, Error>;