sark_http/h1/head/request/pool/
meta.rs1use std::{ops, str};
2
3use o3::buffer::{
4 pool,
5 pool::{owners, state},
6};
7
8use crate::h1::{
9 head::request::{offers, pool::Layout},
10 switch,
11};
12
13pub struct Meta<'d> {
15 pub(in crate::h1::head::request) bytes:
16 pool::Span<owners::Plain<pool::Layout>, pool::Borrowed<'d>, state::Uninit>,
17}
18
19impl<'d> Meta<'d> {
20 pub fn method(&self) -> &str {
21 let layout = self.layout();
22 self.text(0..layout.method_end())
23 }
24
25 pub fn target(&self) -> &str {
26 let layout = self.layout();
27 self.text(layout.target_start()..layout.target_end())
28 }
29
30 pub fn transition(&self) -> switch::Intent {
31 self.layout().transition()
32 }
33
34 pub fn select(
35 &self,
36 selected: &[u8],
37 ) -> Result<Option<switch::Selection>, switch::UpgradeError> {
38 offers::View::from_meta(self)
39 .map(|view| switch::Selection::from_offers(view, selected))
40 .transpose()
41 }
42
43 pub(in crate::h1::head::request) fn layout(&self) -> Layout {
44 unsafe {
47 self.bytes
48 .as_slice()
49 .as_ptr()
50 .cast::<Layout>()
51 .read_unaligned()
52 }
53 }
54
55 pub(in crate::h1::head::request) fn data(&self) -> &[u8] {
56 unsafe { self.bytes.as_slice().get_unchecked(Layout::BYTES..) }
58 }
59
60 fn text(&self, range: ops::Range<usize>) -> &str {
61 unsafe { str::from_utf8_unchecked(self.data().get_unchecked(range)) }
64 }
65}
66
67const _: () = assert!(size_of::<Meta<'static>>() == 2 * size_of::<usize>());