fire_http/into/
into_response.rs1use crate::header::{Mime, StatusCode};
2use crate::{Body, Response};
3
4use bytes::Bytes;
5
6pub trait IntoResponse {
7 fn into_response(self) -> Response;
8}
9
10macro_rules! into_response {
11 ($self:ident: $type:ty $b:block) => (
12 impl IntoResponse for $type {
13 fn into_response($self) -> Response { $b }
14 }
15 )
16}
17
18into_response!(self: Response { self });
19into_response!(self: StatusCode { self.into() });
20into_response!(self: Body { self.into() });
21
22into_response!(self: &'static str {
23 Response::builder()
24 .content_type(Mime::TEXT)
25 .body(self)
26 .build()
27});
28
29into_response!(self: String {
30 Response::builder()
31 .content_type(Mime::TEXT)
32 .body(self)
33 .build()
34});
35
36into_response!(self: Vec<u8> {
37 Response::builder()
38 .content_type(Mime::BINARY)
39 .body(self)
40 .build()
41});
42
43into_response!(self: Bytes {
44 Response::builder()
45 .content_type(Mime::BINARY)
46 .body(self)
47 .build()
48});
49
50into_response!(self: () {
51 Body::new().into()
52});