Skip to main content

sark_http/request/
raw.rs

1use core::ops;
2
3use crate::{
4    field::metadata::{
5        packed,
6        section::{
7            self, rules,
8            state::{RetainedHead, Selected},
9            storage::{self, Block},
10        },
11    },
12    request::{Bound, Error, Layout, Source},
13};
14
15/// Consumes the exact retained request admission and its immutable owner.
16pub trait Bind: Sized {
17    type Owner: Source;
18
19    ///
20    /// # Safety
21    /// Self must come from the native decoder and a closed policy preserving native value and final section admission; these exact original field ranges must come from its native iteration or private selection populated only by that decoder's Commit values tagging actual wire names.
22    unsafe fn try_bind(
23        self,
24        path: Option<ops::Range<usize>>,
25        path_len: Option<usize>,
26        pseudo: Option<ops::Range<usize>>,
27        host: Option<ops::Range<usize>>,
28    ) -> Result<Bound<Self::Owner>, Error>;
29}
30
31impl Bind for RetainedHead<packed::Decoded, Selected<rules::RetainRaw>> {
32    type Owner = packed::Decoded;
33
34    unsafe fn try_bind(
35        self,
36        path: Option<ops::Range<usize>>,
37        path_len: Option<usize>,
38        pseudo: Option<ops::Range<usize>>,
39        host: Option<ops::Range<usize>>,
40    ) -> Result<Bound<Self::Owner>, Error> {
41        let (owner, _, plan) = self.into_parts();
42        let layout = Layout::from_kept(owner.as_bytes(), path, path_len, pseudo, host, plan)?;
43        Ok(Bound { owner, layout })
44    }
45}
46
47impl<P: section::Policy<Block = storage::Fields>> Bind
48    for RetainedHead<storage::Fields, Selected<P>>
49{
50    type Owner = storage::Bytes;
51
52    unsafe fn try_bind(
53        self,
54        path: Option<ops::Range<usize>>,
55        path_len: Option<usize>,
56        pseudo: Option<ops::Range<usize>>,
57        host: Option<ops::Range<usize>>,
58    ) -> Result<Bound<Self::Owner>, Error> {
59        let (fields, _, plan) = self.into_parts();
60        let owner = fields.into_bytes();
61        let layout = Layout::from_kept(owner.as_bytes(), path, path_len, pseudo, host, plan)?;
62        Ok(Bound { owner, layout })
63    }
64}