pub struct ETag {
pub value: String,
pub weak: bool,
}Expand description
An HTTP entity tag as defined by RFC 7232 §2.3.
An ETag is either strong (default) or weak (prefixed with W/).
Strong ETags require byte-for-byte equality; weak ETags indicate semantic
equivalence only.
Fields§
§value: StringThe opaque tag value (without surrounding quotes).
weak: boolWhether this is a weak ETag.
Implementations§
Source§impl ETag
impl ETag
Sourcepub fn strong(value: impl Into<String>) -> Self
pub fn strong(value: impl Into<String>) -> Self
Construct a strong ETag.
The serialized form is "<value>" (with surrounding double-quotes).
use api_bones::etag::ETag;
let tag = ETag::strong("v1");
assert_eq!(tag.to_string(), "\"v1\"");Sourcepub fn weak(value: impl Into<String>) -> Self
pub fn weak(value: impl Into<String>) -> Self
Construct a weak ETag.
The serialized form is W/"<value>".
use api_bones::etag::ETag;
let tag = ETag::weak("v1");
assert_eq!(tag.to_string(), "W/\"v1\"");Sourcepub fn matches(&self, other: &Self) -> bool
pub fn matches(&self, other: &Self) -> bool
Compare two ETags according to RFC 7232 §2.3 comparison rules.
Strong comparison: both must be strong and have the same value. Weak comparison: the values must match regardless of weakness.
This method uses strong comparison: returns true only when both
ETags are strong and their values are identical.
use api_bones::etag::ETag;
let a = ETag::strong("abc");
let b = ETag::strong("abc");
assert!(a.matches(&b));
// Weak tags never match under strong comparison.
let w = ETag::weak("abc");
assert!(!a.matches(&w));Sourcepub fn matches_weak(&self, other: &Self) -> bool
pub fn matches_weak(&self, other: &Self) -> bool
Weak comparison per RFC 7232 §2.3: values match regardless of strength.
use api_bones::etag::ETag;
let strong = ETag::strong("abc");
let weak = ETag::weak("abc");
assert!(strong.matches_weak(&weak));
assert!(weak.matches_weak(&strong));