#shuttle-service #tower

shuttle-tower

Service implementation to run a tower webserver on shuttle

27 breaking releases

0.39.0 Feb 14, 2024
0.37.0 Jan 24, 2024
0.35.2 Dec 21, 2023
0.34.1 Nov 29, 2023
0.13.0 Mar 27, 2023

#383 in HTTP server

Download history 29/week @ 2023-11-02 33/week @ 2023-11-09 46/week @ 2023-11-16 104/week @ 2023-11-23 118/week @ 2023-11-30 108/week @ 2023-12-07 49/week @ 2023-12-14 91/week @ 2023-12-21 3/week @ 2023-12-28 69/week @ 2024-01-04 10/week @ 2024-01-11 35/week @ 2024-01-18 62/week @ 2024-01-25 70/week @ 2024-02-01 138/week @ 2024-02-08 510/week @ 2024-02-15

806 downloads per month

Apache-2.0

5KB

Shuttle service integration for the Tower framework.

Example

use std::convert::Infallible;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};

#[derive(Clone)]
struct HelloWorld;

impl tower::Service<hyper::Request<hyper::Body>> for HelloWorld {
    type Response = hyper::Response<hyper::Body>;
    type Error = Infallible;
    type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + Sync>>;

    fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
        Poll::Ready(Ok(()))
    }

    fn call(&mut self, _req: hyper::Request<hyper::Body>) -> Self::Future {
        let body = hyper::Body::from("Hello, world!");
        let resp = hyper::Response::builder()
            .status(200)
            .body(body)
            .expect("Unable to create the `hyper::Response` object");

        let fut = async { Ok(resp) };

        Box::pin(fut)
    }
}

#[shuttle_runtime::main]
async fn tower() -> shuttle_tower::ShuttleTower<HelloWorld> {
    let service = HelloWorld;

    Ok(service.into())
}

Dependencies

~24–38MB
~653K SLoC