pub fn inject_fields(
doc: &mut Value,
fields: &[(FieldName, Value)],
) -> Result<(), RewriteError>Expand description
Inserts each (name, value) into the top-level object of doc.
A field that already exists is a RewriteError::ReservedFieldCollision,
not an overwrite: a client must not be able to pre-seed a tenancy field and
defeat isolation (docs/03).
§Errors
Returns RewriteError::NotAnObject if doc is not a JSON object, or
RewriteError::ReservedFieldCollision if a field is already present.
§Examples
use serde_json::{json, Value};
use osproxy_core::FieldName;
use osproxy_rewrite::inject_fields;
let mut doc = json!({ "msg": "hi" });
inject_fields(&mut doc, &[(FieldName::from("_tenant"), Value::from("acme"))]).unwrap();
assert_eq!(doc["_tenant"], json!("acme"));