Skip to main content

FieldName

Enum FieldName 

Source
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§

Source§

impl<'a, S> FieldName<'a, S>

Source

pub fn as_str(&self) -> &'a str

The name’s text.

Trait Implementations§

Source§

impl<S> Clone for FieldName<'_, S>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S> Copy for FieldName<'_, S>

Source§

impl<S> Debug for FieldName<'_, S>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S> Eq for FieldName<'_, S>

Source§

impl<S> PartialEq for FieldName<'_, S>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<'a, S> Forget for FieldName<'a, S>

§

impl<'a, S> Freeze for FieldName<'a, S>

§

impl<'a, S> RefUnwindSafe for FieldName<'a, S>

§

impl<'a, S> Send for FieldName<'a, S>

§

impl<'a, S> Sync for FieldName<'a, S>

§

impl<'a, S> Unpin for FieldName<'a, S>

§

impl<'a, S> UnsafeUnpin for FieldName<'a, S>

§

impl<'a, S> UnwindSafe for FieldName<'a, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.