argan_core/response/
mod.rs1use http::{HeaderName, HeaderValue};
6
7use crate::body::Body;
8
9pub use http::response::Builder;
12
13mod error;
16pub use error::{ErrorResponse, ResponseError};
17
18mod impls;
19
20pub type Response<B = Body> = http::response::Response<B>;
24pub type ResponseHeadParts = http::response::Parts;
25
26pub type BoxedErrorResponse = Box<dyn ErrorResponse + Send + Sync>;
27pub type ResponseResult = Result<Response, BoxedErrorResponse>;
28
29pub trait IntoResponseHeadParts {
37 fn into_response_head(
38 self,
39 head: ResponseHeadParts,
40 ) -> Result<ResponseHeadParts, BoxedErrorResponse>;
41}
42
43pub trait IntoResponse {
48 fn into_response(self) -> Response;
49}
50
51impl IntoResponse for Response {
52 fn into_response(self) -> Response {
53 self
54 }
55}
56
57pub trait IntoResponseResult {
62 fn into_response_result(self) -> Result<Response, BoxedErrorResponse>;
63}
64
65impl<R, E> IntoResponseResult for Result<R, E>
66where
67 R: IntoResponseResult,
68 E: Into<BoxedErrorResponse>,
69{
70 fn into_response_result(self) -> Result<Response, BoxedErrorResponse> {
71 self
72 .map_err(Into::into)
73 .and_then(IntoResponseResult::into_response_result)
74 }
75}
76
77impl<R> IntoResponseResult for R
78where
79 R: IntoResponse,
80{
81 fn into_response_result(self) -> Result<Response, BoxedErrorResponse> {
82 Ok(self.into_response())
83 }
84}
85
86