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<const PREFIX: usize> Bind
32    for RetainedHead<
33        packed::Decoded<o3::buffer::pool::Span, PREFIX>,
34        Selected<rules::RetainRaw<PREFIX>>,
35    >
36{
37    type Owner = packed::Decoded<o3::buffer::pool::Span, PREFIX>;
38
39    unsafe fn try_bind(
40        self,
41        path: Option<ops::Range<usize>>,
42        path_len: Option<usize>,
43        pseudo: Option<ops::Range<usize>>,
44        host: Option<ops::Range<usize>>,
45    ) -> Result<Bound<Self::Owner>, Error> {
46        let (owner, _, plan) = self.into_parts();
47        let layout = Layout::from_kept(owner.as_bytes(), path, path_len, pseudo, host, plan)?;
48        Ok(Bound { owner, layout })
49    }
50}
51
52impl<P: section::Policy<Block = storage::Fields>> Bind
53    for RetainedHead<storage::Fields, Selected<P>>
54{
55    type Owner = storage::Bytes;
56
57    unsafe fn try_bind(
58        self,
59        path: Option<ops::Range<usize>>,
60        path_len: Option<usize>,
61        pseudo: Option<ops::Range<usize>>,
62        host: Option<ops::Range<usize>>,
63    ) -> Result<Bound<Self::Owner>, Error> {
64        let (fields, _, plan) = self.into_parts();
65        let owner = fields.into_bytes();
66        let layout = Layout::from_kept(owner.as_bytes(), path, path_len, pseudo, host, plan)?;
67        Ok(Bound { owner, layout })
68    }
69}