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>
impl<'a> EntityTag<'a>
Sourcepub fn parse(value: &'a [u8]) -> Result<Self, ParseError>
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.
Sourcepub const fn strong(opaque: &'a [u8]) -> Result<Self, ParseError>
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.
Sourcepub const fn weak(opaque: &'a [u8]) -> Result<Self, ParseError>
pub const fn weak(opaque: &'a [u8]) -> Result<Self, ParseError>
Sourcepub fn strong_eq(&self, other: &EntityTag<'_>) -> bool
pub fn strong_eq(&self, other: &EntityTag<'_>) -> bool
Strong comparison (RFC 9110 section 8.8.3.2): both strong and equal.
Sourcepub fn weak_eq(&self, other: &EntityTag<'_>) -> bool
pub fn weak_eq(&self, other: &EntityTag<'_>) -> bool
Weak comparison: equal opaque bytes, either may be weak.
Sourcepub fn write_to(&self, out: &mut impl Sink) -> Result<(), WriteError>
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§
impl<'a> Copy for EntityTag<'a>
impl<'a> Eq for EntityTag<'a>
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> 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