Skip to main content

EntityTag

Struct EntityTag 

Source
pub struct EntityTag<'a> { /* private fields */ }
Expand description

An entity tag: a weak flag and the opaque bytes between the quotes.

§Examples

use parse_net::EntityTag;

let t = EntityTag::parse(b"W/\"abc\"")?;
assert!(t.is_weak());
assert_eq!(t.opaque(), b"abc");
assert!(t.weak_eq(&EntityTag::strong(b"abc")?));
assert!(!t.strong_eq(&EntityTag::strong(b"abc")?));

Implementations§

Source§

impl<'a> EntityTag<'a>

Source

pub fn parse(value: &'a [u8]) -> Result<Self, ParseError>

Parses [ "W/" ] DQUOTE *etagc DQUOTE (OWS around it stripped). W/ is case-sensitive.

§Errors

ErrorKind::InvalidEntityTag (a lowercase w/, no quotes, a byte outside etagc, W/ "a"); ErrorKind::TrailingData.

Source

pub const fn strong(opaque: &'a [u8]) -> Result<Self, ParseError>

A strong tag with the given opaque bytes.

§Errors

ErrorKind::InvalidEntityTag at the first byte that is not an etagc.

Source

pub const fn weak(opaque: &'a [u8]) -> Result<Self, ParseError>

A weak tag with the given opaque bytes.

§Errors

As strong.

Source

pub const fn is_weak(&self) -> bool

Whether the tag is weak (W/).

Source

pub const fn opaque(&self) -> &'a [u8] ⓘ

The opaque bytes, without the quotes.

Source

pub fn strong_eq(&self, other: &EntityTag<'_>) -> bool

Strong comparison (RFC 9110 section 8.8.3.2): both strong and equal.

Source

pub fn weak_eq(&self, other: &EntityTag<'_>) -> bool

Weak comparison: equal opaque bytes, either may be weak.

Source

pub fn write_to(&self, out: &mut impl Sink) -> Result<(), WriteError>

Writes W/"..." or "...".

§Errors

WriteError::Full; nothing is written when the sink reports its room.

§Examples
use parse_net::{EntityTag, SliceSink};

let mut buf = [0u8; 16];
let mut out = SliceSink::new(&mut buf);
EntityTag::weak(b"v1")?.write_to(&mut out).expect("room");
assert_eq!(out.written(), b"W/\"v1\"");

Trait Implementations§

Source§

impl<'a> Clone for EntityTag<'a>

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<'a> Copy for EntityTag<'a>

Source§

impl<'a> Debug for EntityTag<'a>

Source§

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

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

impl<'a> Eq for EntityTag<'a>

Source§

impl<'a> Hash for EntityTag<'a>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> PartialEq for EntityTag<'a>

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

impl<'a> StructuralPartialEq for EntityTag<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for EntityTag<'a>

§

impl<'a> RefUnwindSafe for EntityTag<'a>

§

impl<'a> Send for EntityTag<'a>

§

impl<'a> Sync for EntityTag<'a>

§

impl<'a> Unpin for EntityTag<'a>

§

impl<'a> UnsafeUnpin for EntityTag<'a>

§

impl<'a> UnwindSafe for EntityTag<'a>

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.