Skip to main content

sark_core/http/response/
owned_shape.rs

1use std::rc::Rc;
2
3use http::{HeaderName, HeaderValue, StatusCode};
4use o3::buffer::{Bytes, Owned, Retained, Shared};
5
6use super::super::__private::{self, GeneratedResponse, OwnedValue};
7use super::{Chunked, InlineHeaderValue, Response, Serve, Shape};
8
9pub trait OwnedShape: super::super::__private::OwnedShape + 'static {
10    type Shape: Shape<'static>;
11
12    const BODY_KIND: super::super::body_kind::ResponseKind;
13
14    fn into_shape(self) -> Self::Shape;
15}
16
17impl<T> __private::OwnedShape for T
18where
19    T: GeneratedResponse,
20    T::Fields: OwnedValue,
21{
22}
23
24impl<T> OwnedShape for T
25where
26    T: GeneratedResponse,
27    T::Fields: OwnedValue,
28{
29    type Shape = T::Shape;
30
31    const BODY_KIND: super::super::body_kind::ResponseKind = T::BODY_KIND;
32
33    fn into_shape(self) -> Self::Shape {
34        self.into_owned_shape()
35    }
36}
37
38impl super::super::__private::OwnedShape for Response {}
39
40impl OwnedShape for Response {
41    type Shape = Serve;
42
43    const BODY_KIND: super::super::body_kind::ResponseKind =
44        super::super::body_kind::ResponseKind::Inline;
45
46    fn into_shape(self) -> Self::Shape {
47        self.into()
48    }
49}
50
51impl super::super::__private::OwnedShape for Chunked {}
52
53impl OwnedShape for Chunked {
54    type Shape = Self;
55
56    const BODY_KIND: super::super::body_kind::ResponseKind =
57        super::super::body_kind::ResponseKind::Inline;
58
59    fn into_shape(self) -> Self::Shape {
60        self
61    }
62}
63
64impl OwnedValue for bool {}
65impl OwnedValue for char {}
66impl OwnedValue for f32 {}
67impl OwnedValue for f64 {}
68impl OwnedValue for i8 {}
69impl OwnedValue for i16 {}
70impl OwnedValue for i32 {}
71impl OwnedValue for i64 {}
72impl OwnedValue for i128 {}
73impl OwnedValue for isize {}
74impl OwnedValue for u8 {}
75impl OwnedValue for u16 {}
76impl OwnedValue for u32 {}
77impl OwnedValue for u64 {}
78impl OwnedValue for u128 {}
79impl OwnedValue for usize {}
80impl OwnedValue for HeaderName {}
81impl OwnedValue for HeaderValue {}
82impl OwnedValue for InlineHeaderValue {}
83impl OwnedValue for Owned {}
84impl OwnedValue for Shared {}
85impl OwnedValue for StatusCode {}
86impl OwnedValue for String {}
87impl OwnedValue for Bytes<Retained> {}
88
89impl<T: ?Sized> OwnedValue for &'static T {}
90impl<T: OwnedValue, const N: usize> OwnedValue for [T; N] {}
91impl<T: OwnedValue> OwnedValue for Box<T> {}
92impl<T: OwnedValue> OwnedValue for Option<T> {}
93impl<T: OwnedValue> OwnedValue for Rc<T> {}
94impl<T: OwnedValue> OwnedValue for Vec<T> {}
95impl<T: OwnedValue, E: OwnedValue> OwnedValue for Result<T, E> {}
96
97macro_rules! owned_tuples {
98    ($(($($ty:ident),+)),+ $(,)?) => {
99        $(impl<$($ty: OwnedValue),+> OwnedValue for ($($ty,)+) {})+
100    };
101}
102
103owned_tuples! {
104    (T0),
105    (T0, T1),
106    (T0, T1, T2),
107    (T0, T1, T2, T3),
108    (T0, T1, T2, T3, T4),
109    (T0, T1, T2, T3, T4, T5),
110    (T0, T1, T2, T3, T4, T5, T6),
111    (T0, T1, T2, T3, T4, T5, T6, T7),
112    (T0, T1, T2, T3, T4, T5, T6, T7, T8),
113    (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9),
114    (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10),
115    (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11),
116    (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12),
117    (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13),
118    (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14),
119    (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15),
120}