#![allow(dead_code)] // Shared with oxy: not every helper is used yet. //! Tiny JSON building for `--json` outputs: one document on stdout, //! nothing else, with string escaping shared with the hooks payloads. pub use oxy_core::repo::{json_array as arr, json_str as s}; pub fn obj>(pairs: I) -> String { let inner: Vec = pairs.into_iter().map(|(k, v)| format!("{}:{v}", s(k))).collect(); format!("{{{}}}", inner.join(",")) } pub fn b(v: bool) -> String { v.to_string() } pub fn n(v: T) -> String { v.to_string() } pub fn opt(v: Option, f: impl Fn(T) -> String) -> String { match v { Some(x) => f(x), None => "null".into(), } } pub fn hashes(v: &[oxy_core::hash::ChangeHash]) -> String { arr(v.iter().map(|h| s(&h.to_hex()))) }