1use tonic::{Request, Response, Status};
2
3use crate::error::QueryError;
4
5pub trait TryIntoDomain<T> {
6 fn try_into_domain(self) -> Result<T, Status>;
7}
8
9pub trait IntoDomain<T> {
10 fn into_domain(self) -> T;
11}
12
13impl<T, Raw> TryIntoDomain<T> for Request<Raw>
14where
15 T: TryFrom<Raw, Error = QueryError>,
16{
17 fn try_into_domain(self) -> Result<T, Status> {
18 Ok(self.into_inner().try_into()?)
19 }
20}
21
22impl<T, Raw> IntoDomain<T> for Request<Raw>
23where
24 T: From<Raw>,
25{
26 fn into_domain(self) -> T {
27 self.into_inner().into()
28 }
29}
30
31pub trait IntoResponse<Raw>: Sized
32where
33 Self: Into<Raw>,
34{
35 fn into_response(self) -> Result<Response<Raw>, Status> {
36 Ok(Response::new(self.into()))
37 }
38}
39
40impl<T, Raw> IntoResponse<Raw> for T where T: Into<Raw> {}