json_matcher/matchers/
any.rs1use serde_json::Value;
2
3use crate::{JsonMatcher, JsonMatcherError};
4
5pub struct AnyMatcher {
6 not_null: bool,
7}
8
9impl Default for AnyMatcher {
10 fn default() -> Self {
11 Self::new()
12 }
13}
14
15impl AnyMatcher {
16 pub fn new() -> Self {
17 Self { not_null: false }
18 }
19
20 pub fn not_null() -> Self {
21 Self { not_null: true }
22 }
23}
24
25impl JsonMatcher for AnyMatcher {
26 fn json_matches(&self, value: &Value) -> Vec<JsonMatcherError> {
27 if self.not_null && value.is_null() {
28 vec![JsonMatcherError::at_root("Expected non-null value")]
29 } else {
30 vec![]
31 }
32 }
33}