Skip to main content

sark_http/payload/response/
statics.rs

1use o3::buffer::resident::bound;
2
3use crate::payload::{
4    fixed,
5    response::{dispatch, headers, status::Code},
6};
7
8/// Static response retaining every generated field in its original type.
9#[derive(Copy)]
10pub struct Direct<'body, H> {
11    status: Code,
12    fields: H,
13    body: fixed::Body<'body>,
14}
15
16impl<H: Copy> Clone for Direct<'_, H> {
17    fn clone(&self) -> Self {
18        *self
19    }
20}
21
22impl<'body, H> Direct<'body, H> {
23    pub fn new(status: Code, fields: H, body: fixed::Body<'body>) -> Self {
24        Self {
25            status,
26            fields,
27            body,
28        }
29    }
30
31    pub fn status(&self) -> Code {
32        self.status
33    }
34
35    pub fn body(&self) -> &fixed::Body<'body> {
36        &self.body
37    }
38}
39
40impl<'body, 'req, 'd, H: headers::Source> dispatch::IntoOutput<'req, 'd> for Direct<'body, H>
41where
42    'body: 'd,
43{
44    type Output = Self;
45
46    fn into_output(self) -> Self::Output {
47        self
48    }
49}
50
51impl<'body, 'req, 'd, H: headers::Source> dispatch::Complete<'req, 'd> for Direct<'body, H>
52where
53    'body: 'd,
54{
55    const BODY: crate::payload::Kind = crate::payload::Kind::Static;
56
57    type Bound = bound::AtMost<0>;
58
59    fn complete<S>(self, sink: S) -> Result<S::Output, S::Error>
60    where
61        S: dispatch::Accept<'d>,
62    {
63        let Self {
64            status,
65            fields,
66            body,
67        } = self;
68        dispatch::Accept::statics(sink, status, fields, body)
69    }
70}