1use std::future::Future;
2
3use bytes::Bytes;
4
5use crate::handler::HandlerError;
6pub use crate::layer::ErasedCall;
7use crate::layer::{LayerFn, Next, ServiceBody};
8use crate::service::{HandlerService, Operation, OperationContract};
9
10pub fn unary(local_name: &str, contract: OperationContract, call: ErasedCall) -> HandlerService {
11 service(local_name, Operation::Unary, contract, call)
12}
13
14pub fn streaming(
15 local_name: &str,
16 contract: OperationContract,
17 call: ErasedCall,
18) -> HandlerService {
19 service(local_name, Operation::Streaming, contract, call)
20}
21
22fn service(
23 local_name: &str,
24 operation: Operation,
25 contract: OperationContract,
26 call: ErasedCall,
27) -> HandlerService {
28 HandlerService::declare(local_name, None, None, operation, contract, move |_| {
29 Ok(call)
30 })
31}
32
33pub fn layer<F, Fut>(call: F) -> LayerFn<F>
34where
35 F: Fn(http::Request<Bytes>, Next) -> Fut + Send + Sync + 'static,
36 Fut: Future<Output = Result<http::Response<ServiceBody>, HandlerError>> + Send + 'static,
37{
38 crate::layer::layer_fn(call)
39}
40
41pub fn peer_layer<F, Fut>(call: F) -> crate::peer::PeerLayerFn<F>
42where
43 F: Fn(crate::peer::PeerRequest, crate::peer::PeerNext) -> Fut + Send + Sync + 'static,
44 Fut: Future<Output = Result<crate::peer::PeerRequest, HandlerError>> + Send + 'static,
45{
46 crate::peer::peer_layer_fn(call)
47}