axum_connect/
response.rs

1use prost::Message;
2
3use crate::error::{RpcError, RpcIntoError};
4
5pub type RpcResult<M> = Result<M, RpcError>;
6
7pub trait RpcIntoResponse<T>: Send + Sync + 'static
8where
9    T: Message,
10{
11    fn rpc_into_response(self) -> RpcResult<T>;
12}
13
14impl<T> RpcIntoResponse<T> for T
15where
16    T: Message + 'static,
17{
18    fn rpc_into_response(self) -> RpcResult<T> {
19        Ok(self)
20    }
21}
22
23impl<T, E> RpcIntoResponse<T> for Result<T, E>
24where
25    T: Message + 'static,
26    E: RpcIntoError + Send + Sync + 'static,
27{
28    fn rpc_into_response(self) -> RpcResult<T> {
29        self.map_err(|e| e.rpc_into_error())
30    }
31}