Skip to main content

sark_http/request/
raw.rs

1use core::ops;
2
3use o3::buffer::pool;
4
5use crate::{
6    field::metadata::{
7        packed,
8        section::{
9            rules,
10            state::{RetainedHead, decode::Head},
11            storage::{self, Block},
12        },
13    },
14    request::{Bound, Error, Layout, Source},
15};
16
17/// Consumes the exact retained request admission and its immutable owner.
18pub trait Bind: Sized {
19    type Owner: Source;
20
21    /// # Safety
22    /// Use the sealed native head and its closed policy. Each range must be the exact
23    /// committed value of the corresponding wire field in this head's immutable storage.
24    unsafe fn try_bind(
25        self,
26        path: Option<ops::Range<usize>>,
27        path_len: Option<usize>,
28        pseudo: Option<ops::Range<usize>>,
29        host: Option<ops::Range<usize>>,
30    ) -> Result<Bound<Self::Owner>, Error>;
31}
32
33impl<const PREFIX: usize, S: rules::RawSelection> Bind for Head<rules::RetainRaw<PREFIX, S>> {
34    type Owner = packed::Decoded<pool::Span, PREFIX>;
35
36    unsafe fn try_bind(
37        self,
38        path: Option<ops::Range<usize>>,
39        path_len: Option<usize>,
40        pseudo: Option<ops::Range<usize>>,
41        host: Option<ops::Range<usize>>,
42    ) -> Result<Bound<Self::Owner>, Error> {
43        let (owner, _, plan) = self.into_parts();
44        let layout = Layout::from_kept(owner.as_bytes(), path, path_len, pseudo, host, plan)?;
45        Ok(Bound { owner, layout })
46    }
47}
48
49impl<S> Bind for RetainedHead<storage::Fields, S> {
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_ref(), path, path_len, pseudo, host, plan)?;
62        Ok(Bound { owner, layout })
63    }
64}