Struct headers::util::entity::EntityTag

source ·
pub(crate) struct EntityTag<T = HeaderValue>(T);
Expand description

An entity tag, defined in RFC7232

An entity tag consists of a string enclosed by two literal double quotes. Preceding the first double quote is an optional weakness indicator, which always looks like W/. Examples for valid tags are "xyzzy" and W/"xyzzy".

ABNF

entity-tag = [ weak ] opaque-tag
weak       = %x57.2F ; "W/", case-sensitive
opaque-tag = DQUOTE *etagc DQUOTE
etagc      = %x21 / %x23-7E / obs-text
           ; VCHAR except double quotes, plus obs-text

Comparison

To check if two entity tags are equivalent in an application always use the strong_eq or weak_eq methods based on the context of the Tag. Only use == to check if two tags are identical.

The example below shows the results for a set of entity-tag pairs and both the weak and strong comparison function results:

ETag 1ETag 2Strong ComparisonWeak Comparison
W/"1"W/"1"no matchmatch
W/"1"W/"2"no matchno match
W/"1""1"no matchmatch
"1""1"matchmatch

Tuple Fields§

§0: T

Implementations§

source§

impl<T: AsRef<[u8]>> EntityTag<T>

source

pub(crate) fn tag(&self) -> &[u8]

Get the tag.

source

pub(crate) fn is_weak(&self) -> bool

Return if this is a “weak” tag.

source

pub(crate) fn strong_eq<R>(&self, other: &EntityTag<R>) -> boolwhere R: AsRef<[u8]>,

For strong comparison two entity-tags are equivalent if both are not weak and their opaque-tags match character-by-character.

source

pub(crate) fn weak_eq<R>(&self, other: &EntityTag<R>) -> boolwhere R: AsRef<[u8]>,

For weak comparison two entity-tags are equivalent if their opaque-tags match character-by-character, regardless of either or both being tagged as “weak”.

source

pub(crate) fn parse(src: T) -> Option<Self>

source§

impl EntityTag

source

pub(crate) fn from_owned(val: HeaderValue) -> Option<EntityTag>

source

pub(crate) fn from_val(val: &HeaderValue) -> Option<EntityTag>

Trait Implementations§

source§

impl<T: Clone> Clone for EntityTag<T>

source§

fn clone(&self) -> EntityTag<T>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for EntityTag<T>

source§

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

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

impl<'a> From<&'a EntityTag<HeaderValue>> for HeaderValue

source§

fn from(tag: &'a EntityTag) -> HeaderValue

Converts to this type from the input type.
source§

impl From<EntityTag<HeaderValue>> for HeaderValue

source§

fn from(tag: EntityTag) -> HeaderValue

Converts to this type from the input type.
source§

impl<T: PartialEq> PartialEq<EntityTag<T>> for EntityTag<T>

source§

fn eq(&self, other: &EntityTag<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryFromValues for EntityTag

source§

fn try_from_values<'i, I>(values: &mut I) -> Result<Self, Error>where I: Iterator<Item = &'i HeaderValue>,

Try to convert from the values into an instance of Self.
source§

impl<T: Eq> Eq for EntityTag<T>

source§

impl<T> StructuralEq for EntityTag<T>

source§

impl<T> StructuralPartialEq for EntityTag<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for EntityTag<T>where T: RefUnwindSafe,

§

impl<T> Send for EntityTag<T>where T: Send,

§

impl<T> Sync for EntityTag<T>where T: Sync,

§

impl<T> Unpin for EntityTag<T>where T: Unpin,

§

impl<T> UnwindSafe for EntityTag<T>where T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.