use serde::Serialize;
#[derive(Serialize)]
pub struct JsonEnvelope<T: Serialize> {
pub version: &'static str,
pub status: &'static str,
pub data: T,
}
pub fn print_success<T: Serialize>(data: &T) {
let envelope = JsonEnvelope {
version: "1",
status: "success",
data,
};
println!(
"{}",
serde_json::to_string_pretty(&envelope).unwrap_or_else(|_| "{}".to_string())
);
}
pub fn print_error(err: &str) {
let msg = serde_json::json!({
"version": "1",
"status": "error",
"error": err
});
eprintln!("{}", serde_json::to_string_pretty(&msg).unwrap_or_else(|_| "{}".to_string()));
}