labscript 0.1.0

Prescription PDF generator with e-signature and QR verification
use serde::Serialize;

/// Standard JSON envelope matching labparse/labstore/labassess convention
#[derive(Serialize)]
pub struct JsonEnvelope<T: Serialize> {
    pub version: &'static str,
    pub status: &'static str,
    pub data: T,
}

/// Print a success envelope to stdout
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())
    );
}

/// Print an error envelope to stderr
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()));
}