pub trait JsonMatcher: Debug {
// Required methods
fn matches(&self, value: &Value) -> bool;
fn description(&self) -> String;
}Expand description
Core trait for implementing JSON value matchers.
This trait allows creation of custom matchers for flexible value validation. Implementors must provide both matching logic and a description of the matcher.
§Examples
use json_test::JsonMatcher;
use serde_json::Value;
#[derive(Debug)]
struct DateMatcher;
impl JsonMatcher for DateMatcher {
fn matches(&self, value: &Value) -> bool {
value.as_str()
.map(|s| s.contains("-"))
.unwrap_or(false)
}
fn description(&self) -> String {
"is a date string".to_string()
}
}Required Methods§
Sourcefn description(&self) -> String
fn description(&self) -> String
Returns a human-readable description of the matcher’s criteria.
This description is used in error messages when assertions fail.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".