1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use super::IntoResponse;
use crate::error::{ClientErrorKind, Error};
use crate::Response;

pub trait IntoRouteResult {
	fn into_route_result(self) -> crate::Result<Response>;
}

impl<R, E> IntoRouteResult for Result<R, E>
where
	R: IntoResponse,
	E: Into<Error>,
{
	fn into_route_result(self) -> crate::Result<Response> {
		self.map(|o| o.into_response()).map_err(|e| e.into())
	}
}

impl<R> IntoRouteResult for Option<R>
where
	R: IntoResponse,
{
	fn into_route_result(self) -> crate::Result<Response> {
		match self {
			Some(r) => Ok(r.into_response()),
			None => Err(Error::empty(ClientErrorKind::NotFound)),
		}
	}
}

impl<R> IntoRouteResult for R
where
	R: IntoResponse,
{
	fn into_route_result(self) -> crate::Result<Response> {
		Ok(self.into_response())
	}
}