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.
§Examples
use parse_net::EntityTag;
let t = EntityTag::parse(b" \"xyzzy\" ")?;
assert!(!t.is_weak() && t.opaque() == b"xyzzy");
assert!(EntityTag::parse(b"w/\"xyzzy\"").is_err());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.
§Examples
use parse_net::EntityTag;
assert!(!EntityTag::strong(b"v1")?.is_weak());
assert!(EntityTag::strong(b"a\"b").is_err());Sourcepub const fn weak(opaque: &'a [u8]) -> Result<Self, ParseError>
pub const fn weak(opaque: &'a [u8]) -> Result<Self, ParseError>
Sourcepub const fn is_weak(&self) -> bool
pub const fn is_weak(&self) -> bool
Whether the tag is weak (W/).
§Examples
use parse_net::EntityTag;
assert!(EntityTag::parse(b"W/\"1\"")?.is_weak());
assert!(!EntityTag::parse(b"\"1\"")?.is_weak());Sourcepub const fn opaque(&self) -> &'a [u8] ⓘ
pub const fn opaque(&self) -> &'a [u8] ⓘ
The opaque bytes, without the quotes.
§Examples
use parse_net::EntityTag;
assert_eq!(EntityTag::parse(b"W/\"abc\"")?.opaque(), b"abc");
assert_eq!(EntityTag::parse(b"\"\"")?.opaque(), b"");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.
§Examples
use parse_net::EntityTag;
let a = EntityTag::strong(b"1")?;
assert!(a.strong_eq(&EntityTag::parse(b"\"1\"")?));
assert!(!a.strong_eq(&EntityTag::weak(b"1")?));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.
§Examples
use parse_net::EntityTag;
let (w, s) = (EntityTag::weak(b"1")?, EntityTag::strong(b"1")?);
assert!(w.weak_eq(&s) && !w.weak_eq(&EntityTag::strong(b"2")?));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\"");Source§impl EntityTag<'_>
impl EntityTag<'_>
Sourcepub fn to_owned(&self) -> OwnedEntityTag
Available on crate feature alloc only.
pub fn to_owned(&self) -> OwnedEntityTag
alloc only.Copies the tag into an OwnedEntityTag (one allocation).
§Examples
let input = b"\"abc\"".to_vec();
let owned = parse_net::EntityTag::parse(&input)?.to_owned();
drop(input);
assert!(!owned.as_view().is_weak() && owned.as_view().opaque() == b"abc");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> Forget for EntityTag<'a>
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