Skip to main content

accumulate_i64_fields

Function accumulate_i64_fields 

Source
pub fn accumulate_i64_fields(
    target: &mut Map<String, Value>,
    source: &Map<String, Value>,
    fields: &[&str],
)
Expand description

Adds the named i64 fields from source into target, in place.

For each name in fields, the matching integer in source is added to the matching integer in target (treating a missing target as 0). Fields absent from source, or present but non-integer, are skipped — so target only ever gains the keys that actually carried a number.

§Examples

use serde_json::{json, Map};
use vibe_coding_tracker::utils::accumulate_i64_fields;

let mut target = Map::new();
target.insert("input".into(), json!(10));

let mut source = Map::new();
source.insert("input".into(), json!(5));
source.insert("output".into(), json!(7));

accumulate_i64_fields(&mut target, &source, &["input", "output"]);
assert_eq!(target["input"], json!(15));
assert_eq!(target["output"], json!(7));