I’m happy to announce the 0.6 release of gotham. Below you can find the highlights of all changes. Starting with this release, you can see the full changelog at the GitHub release page: https://github.com/gotham-rs/gotham/releases

Update to Tokio 1.0

This release updates gotham to the Tokio 1.0 release for the most stable async platform that Rust has ever seen! Please refer to the the respective announcements of tokio 1.0 and hyper 0.14 to see what has changed.

Custom Hyper Services

With the new version, you can integrate gotham with all its goodness into custom hyper services. Previously, you had to start the server through gotham’s exposed start methods, which still works, but doesn’t allow for as much customization. This is an excerpt from our new example:

#[derive(Clone)]
struct MyService {
    router: Router,
    addr: SocketAddr,
}

impl Service<Request<Body>> for MyService {
    type Response = Response<Body>;
    type Error = Error;
    type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;

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

    fn call(&mut self, req: Request<Body>) -> Self::Future {
        // NOTE: You don't *have* to use call_handler for this (you could use `router.handle`), but
        // call_handler will catch panics and return en error response.
        let state = State::from_request(req, self.addr);
        call_handler(self.router.clone(), AssertUnwindSafe(state)).boxed()
    }
}

let addr = "127.0.0.1:7878";
let listener = TcpListener::bind(&addr).await?;

loop {
    let (socket, addr) = listener
        .accept()
        .await
        .context("Error accepting connection")?;

    let service = MyService {
        router: router.clone(),
        addr,
    };

    let task = async move {
        Http::new()
            .serve_connection(socket, service)
            .await
            .context("Error serving connection")?;

        Result::<_, Error>::Ok(())
    };

    tokio::spawn(task);
}

Miscellaneous

A huge thanks to everyone that contributed to this release, it wouldn’t be this awesome without your help! If there is something missing in this release that you’d like to see, please reach out to us. You can do that using GitHub issues or Gitter chat, and of course you are more than welcome to hand in Pull Requests. We appreciate every contribution.