Skip to main content

sark_http/payload/response/headers/
head.rs

1use crate::payload::response::{headers, headers::set};
2
3pub struct Template<'a> {
4    fields: &'a [headers::Entry<'a>],
5}
6
7impl<'a> Template<'a> {
8    pub const fn new(fields: &'a [headers::Entry<'a>]) -> Self {
9        Self { fields }
10    }
11
12    fn fields(&self) -> impl Iterator<Item = headers::Entry<'a>> + '_ {
13        self.fields.iter().copied()
14    }
15}
16
17pub struct Head<'req, const N: usize = { set::DEFAULT_CAPACITY }> {
18    template: &'req Template<'req>,
19    headers: set::Set<'req, N>,
20}
21
22impl<'req, const N: usize> Head<'req, N> {
23    pub fn new(template: &'req Template<'req>, headers: set::Set<'req, N>) -> Self {
24        Self { template, headers }
25    }
26
27    fn fields(&self) -> impl Iterator<Item = headers::Entry<'_>> {
28        self.template.fields().chain(self.headers.fields())
29    }
30}
31
32impl<const N: usize> headers::Source for Head<'_, N> {
33    fn emit<'field>(&'field self, sink: &mut impl headers::Sink<'field>) {
34        for field in self.fields() {
35            sink.entry(field);
36        }
37    }
38}