webpage_quality_analyzer 1.0.2

High-performance webpage quality analyzer with 115 comprehensive metrics - Rust library with WASM, C++, and Python bindings
Documentation
//! Output customization (Phase 6 features)

use std::os::raw::c_char;
use std::ptr;

use super::conversions::{cast_report, rust_str_to_c};
use super::errors::set_last_error;
use super::types::CReport;

/// Export report as compact JSON
///
/// # Returns
/// Pointer to JSON string. Caller must free with `wqa_free_string()`.
#[no_mangle]
pub extern "C" fn wqa_report_to_compact_json(report: *const CReport) -> *mut c_char {
    if report.is_null() {
        set_last_error("Null report provided".to_string());
        return ptr::null_mut();
    }

    let internal = unsafe {
        match cast_report(report) {
            Some(r) => r,
            None => return ptr::null_mut(),
        }
    };

    match internal.report.to_compact_json() {
        Ok(json) => rust_str_to_c(&json),
        Err(e) => {
            set_last_error(format!("JSON serialization failed: {}", e));
            ptr::null_mut()
        }
    }
}

/// Export report as readable (pretty-printed) JSON
#[no_mangle]
pub extern "C" fn wqa_report_to_readable_json(report: *const CReport) -> *mut c_char {
    if report.is_null() {
        set_last_error("Null report provided".to_string());
        return ptr::null_mut();
    }

    let internal = unsafe {
        match cast_report(report) {
            Some(r) => r,
            None => return ptr::null_mut(),
        }
    };

    match internal.report.to_readable_json() {
        Ok(json) => rust_str_to_c(&json),
        Err(e) => {
            set_last_error(format!("JSON serialization failed: {}", e));
            ptr::null_mut()
        }
    }
}