Check if container JSON contains the contained JSON
(container: &JsonValue, contained: &JsonValue)
| 1526 | |
| 1527 | /// Check if container JSON contains the contained JSON |
| 1528 | fn json_contains(container: &JsonValue, contained: &JsonValue) -> bool { |
| 1529 | match (container, contained) { |
| 1530 | (JsonValue::Object(cont_map), JsonValue::Object(item_map)) => { |
| 1531 | // All keys in item must exist in container with same values |
| 1532 | item_map.iter().all(|(key, value)| { |
| 1533 | cont_map.get(key).is_some_and(|v| json_contains(v, value)) |
| 1534 | }) |
| 1535 | } |
| 1536 | (JsonValue::Array(cont_arr), JsonValue::Array(item_arr)) => { |
| 1537 | // All items in item_arr must be contained in cont_arr |
| 1538 | item_arr.iter().all(|item| { |
| 1539 | cont_arr.iter().any(|cont_item| json_contains(cont_item, item)) |
| 1540 | }) |
| 1541 | } |
| 1542 | (JsonValue::Array(cont_arr), item) => { |
| 1543 | // Check if array contains the single item |
| 1544 | cont_arr.iter().any(|cont_item| json_contains(cont_item, item)) |
| 1545 | } |
| 1546 | _ => container == contained, |
| 1547 | } |
| 1548 | } |
| 1549 | |
| 1550 | /// Register json_populate_record function |
| 1551 | fn register_json_populate_record(conn: &Connection) -> Result<()> { |
no test coverage detected