pub struct MatcherValue {
pub value: String,
pub not: bool,
pub optional: bool,
}Expand description
A single matcher value for a request header, query-string parameter, cookie or path parameter.
MockServer’s plain-string wire form encodes negation and optionality as
leading markers — ! negates and ? marks optional — and the server strips
them unconditionally when reading. A value whose own first character is !
or ? therefore cannot be sent as a bare string:
header("X-Tag", "!foo") is read back as “X-Tag is
anything but foo”, which matches almost every request, so the expectation
silently passes for the wrong reason instead of failing.
MatcherValue keeps the value and the flags apart and serialises to the
object form ({"not":false,"value":"!foo"}) only when the plain form would
be misread. Every value that already round-trips through the plain form stays
byte-identical on the wire, so existing expectations are unaffected.
Use literal for an exact value, not_literal
to negate one, and optional_literal for an
optional exact value:
use mockserver_client::{HttpRequest, MatcherValue};
let request = HttpRequest::new()
.header_matcher("X-Tag", MatcherValue::literal("!foo")) // X-Tag IS "!foo"
.header_matcher("X-Env", MatcherValue::not_literal("dev")); // X-Env is NOT "dev"Fields§
§value: StringThe matcher text, taken verbatim — markers in it are not parsed.
not: boolNegate the matcher ("not": true).
optional: boolMark the header/parameter/cookie as optional ("optional": true).
Implementations§
Source§impl MatcherValue
impl MatcherValue
Sourcepub fn literal(value: impl Into<String>) -> Self
pub fn literal(value: impl Into<String>) -> Self
A matcher for exactly value, even when it starts with ! or ?.
Sourcepub fn not_literal(value: impl Into<String>) -> Self
pub fn not_literal(value: impl Into<String>) -> Self
A matcher that matches anything except exactly value.
Sourcepub fn optional_literal(value: impl Into<String>) -> Self
pub fn optional_literal(value: impl Into<String>) -> Self
A matcher for exactly value that need not be present.
Trait Implementations§
Source§impl Clone for MatcherValue
impl Clone for MatcherValue
Source§fn clone(&self) -> MatcherValue
fn clone(&self) -> MatcherValue
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MatcherValue
impl Debug for MatcherValue
Source§impl Default for MatcherValue
impl Default for MatcherValue
Source§fn default() -> MatcherValue
fn default() -> MatcherValue
Source§impl<'de> Deserialize<'de> for MatcherValue
impl<'de> Deserialize<'de> for MatcherValue
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Display for MatcherValue
impl Display for MatcherValue
impl Eq for MatcherValue
Source§impl From<&str> for MatcherValue
impl From<&str> for MatcherValue
Source§impl From<String> for MatcherValue
impl From<String> for MatcherValue
Source§impl PartialEq for MatcherValue
impl PartialEq for MatcherValue
Source§impl Serialize for MatcherValue
impl Serialize for MatcherValue
impl StructuralPartialEq for MatcherValue
Auto Trait Implementations§
impl Freeze for MatcherValue
impl RefUnwindSafe for MatcherValue
impl Send for MatcherValue
impl Sync for MatcherValue
impl Unpin for MatcherValue
impl UnsafeUnpin for MatcherValue
impl UnwindSafe for MatcherValue
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.