41 breaking releases

new 0.53.0 Mar 12, 2025
0.51.0 Jan 10, 2025
0.49.0 Nov 12, 2024
0.47.0 Jul 23, 2024
0.13.0 Mar 27, 2023

#1430 in HTTP server

Download history 53/week @ 2024-11-13 9/week @ 2024-11-20 3/week @ 2024-11-27 14/week @ 2024-12-04 26/week @ 2024-12-11 51/week @ 2025-01-01 206/week @ 2025-01-08 4/week @ 2025-01-15 51/week @ 2025-01-29 47/week @ 2025-02-05 215/week @ 2025-02-12 2/week @ 2025-02-26

315 downloads per month

Apache-2.0

47KB
812 lines

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

~13–25MB
~358K SLoC