macro_rules! primitive {
($matcher:expr) => { ... };
}
Expand description
Matches a JSON value (string, number, or boolean) against the given matcher.
This macro enables matching specific primitive values inside a JSON structure by delegating to a matcher for the corresponding Rust type. It supports:
String
values (e.g.json::primitive!(eq("hello"))
)Number
values asi64
orf64
(e.g.json::primitive!(ge(0))
)Boolean
values (e.g.json::primitive!(eq(true))
)
Fails if the value is not of the expected JSON type.
ยงExample
let data = j!({"active": true, "count": 3});
verify_that!(data["active"], json::primitive!(eq(true)));
verify_that!(data["count"], json::primitive!(ge(0)));