restate_sdk/
hyper.rs

1//! Hyper integration.
2
3use crate::endpoint;
4use crate::endpoint::{Endpoint, HandleOptions, ProtocolMode};
5
6use http::{Request, Response};
7use hyper::body::Incoming;
8use hyper::service::Service;
9use std::convert::Infallible;
10use std::future::{ready, Ready};
11
12/// Wraps [`Endpoint`] to implement hyper [`Service`].
13#[derive(Clone)]
14pub struct HyperEndpoint(Endpoint);
15
16impl HyperEndpoint {
17    pub fn new(endpoint: Endpoint) -> Self {
18        Self(endpoint)
19    }
20}
21
22impl Service<Request<Incoming>> for HyperEndpoint {
23    type Response = Response<endpoint::ResponseBody>;
24    type Error = Infallible;
25    type Future = Ready<Result<Self::Response, Self::Error>>;
26
27    fn call(&self, req: Request<Incoming>) -> Self::Future {
28        ready(Ok(self.0.handle_with_options(
29            req,
30            HandleOptions {
31                protocol_mode: ProtocolMode::BidiStream,
32            },
33        )))
34    }
35}