Skip to main content

sark_http/payload/response/
fixed.rs

1use o3::buffer::resident::bound;
2
3use crate::payload::response::{Body, dispatch, headers, status::Code};
4
5/// Response retaining its generated field types without an erased value enum.
6pub struct Direct<H, B> {
7    status: Code,
8    fields: H,
9    body: B,
10}
11
12impl<H, B> Direct<H, B> {
13    pub fn new(status: Code, fields: H, body: B) -> Self {
14        Self {
15            status,
16            fields,
17            body,
18        }
19    }
20
21    pub fn status(&self) -> Code {
22        self.status
23    }
24
25    pub fn body(&self) -> &B {
26        &self.body
27    }
28}
29
30impl<'req, 'd, H, B> dispatch::IntoOutput<'req, 'd> for Direct<H, B>
31where
32    H: headers::Source,
33    B: Body<'d>,
34{
35    type Output = Self;
36
37    fn into_output(self) -> Self::Output {
38        self
39    }
40}
41
42impl<'req, 'd, H, B> dispatch::Complete<'req, 'd> for Direct<H, B>
43where
44    H: headers::Source,
45    B: Body<'d>,
46{
47    const BODY: crate::payload::Kind = crate::payload::Kind::Inline;
48    type Bound = bound::Unbounded;
49
50    fn complete<S>(self, sink: S) -> Result<S::Output, S::Error>
51    where
52        S: dispatch::Accept<'d>,
53    {
54        let Self {
55            status,
56            fields,
57            body,
58        } = self;
59        dispatch::Accept::fixed(sink, status, fields, body)
60    }
61}