OXYGENHUB

Coverage / src/cli/json.rs 0.0%

0 of 20 lines run, 0 of 14 functions · run #16 on main · run missed

1
#![allow(dead_code)] // Shared with oxy: not every helper is used yet.
2
//! Tiny JSON building for `--json` outputs: one document on stdout,
3
//! nothing else, with string escaping shared with the hooks payloads.
4
5
pub use oxy_core::repo::{json_array as arr, json_str as s};
6
70×
pub fn obj<I: IntoIterator<Item = (&'static str, String)>>(pairs: I) -> String {
80×
    let inner: Vec<String> = pairs.into_iter().map(|(k, v)| format!("{}:{v}", s(k))).collect();
90×
    format!("{{{}}}", inner.join(","))
100×
}
110×
pub fn b(v: bool) -> String {
120×
    v.to_string()
130×
}
140×
pub fn n<T: std::fmt::Display>(v: T) -> String {
150×
    v.to_string()
160×
}
170×
pub fn opt<T>(v: Option<T>, f: impl Fn(T) -> String) -> String {
180×
    match v {
190×
        Some(x) => f(x),
200×
        None => "null".into(),
21
    }
220×
}
230×
pub fn hashes(v: &[oxy_core::hash::ChangeHash]) -> String {
240×
    arr(v.iter().map(|h| s(&h.to_hex())))
250×
}