pub enum FieldName<'a, S> {
Text(&'a str),
Indexed(StaticTableEntry<S>),
}Expand description
How a decoder with a static table names one field for section S: by an entry of the table, classified for S, or as text when the name was sent literally.
use base_message::{FieldName, FieldSection, FieldType, FieldValueError, StaticTableEntry, ascii_text, combination::Singleton, static_table_entries};
struct Text(String);
impl FieldType<'_> for Text {
type Combination = Singleton;
fn parse(value: &[u8]) -> Result<Self, FieldValueError> {
Ok(Self(ascii_text(value)?.to_owned()))
}
}
#[derive(FieldSection)]
struct Request {
#[field("host")]
host: Option<Text>,
#[field("x-request-id")]
request_id: Option<Text>,
}
const TABLE: [StaticTableEntry<Request>; 1] = static_table_entries::<Request, 1>(&["host"]);
let fields = [(FieldName::Indexed(TABLE[0]), &b"example.com"[..]), (FieldName::Text("x-request-id"), b"abc")];
let request = Request::interpret(fields).unwrap();
assert_eq!(request.request_id.map(|id| id.0).as_deref(), Some("abc"));Variants§
Text(&'a str)
A name sent literally, to match against the section’s declarations.
Indexed(StaticTableEntry<S>)
A name sent as an index into the static table, classified for the section.
Implementations§
Trait Implementations§
impl<S> Copy for FieldName<'_, S>
impl<S> Eq for FieldName<'_, S>
Auto Trait Implementations§
impl<'a, S> Forget for FieldName<'a, S>
impl<'a, S> Freeze for FieldName<'a, S>where
StaticTableEntry<S>: Freeze,
impl<'a, S> RefUnwindSafe for FieldName<'a, S>where
StaticTableEntry<S>: RefUnwindSafe,
impl<'a, S> Send for FieldName<'a, S>where
StaticTableEntry<S>: Send,
impl<'a, S> Sync for FieldName<'a, S>where
StaticTableEntry<S>: Sync,
impl<'a, S> Unpin for FieldName<'a, S>where
StaticTableEntry<S>: Unpin,
impl<'a, S> UnsafeUnpin for FieldName<'a, S>where
StaticTableEntry<S>: UnsafeUnpin,
impl<'a, S> UnwindSafe for FieldName<'a, S>where
StaticTableEntry<S>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more