webpage_quality_analyzer 1.0.2

High-performance webpage quality analyzer with 115 comprehensive metrics - Rust library with WASM, C++, and Python bindings
Documentation
//! Config file loading (Level 3 API)

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

use super::conversions::c_str_to_rust;
use super::errors::set_last_error;
use super::types::{AnalyzerInternal, CAnalyzer};

/// Load analyzer from configuration file (Level 3 API)
///
/// # Arguments
/// * `path` - Path to YAML/JSON/TOML configuration file
///
/// # Returns
/// Pointer to CAnalyzer on success, NULL on failure
#[no_mangle]
pub extern "C" fn wqa_from_config_file(path: *const c_char) -> *mut CAnalyzer {
    if path.is_null() {
        set_last_error("Path cannot be null".to_string());
        return ptr::null_mut();
    }

    let path_str = unsafe {
        match c_str_to_rust(path) {
            Some(s) => s,
            None => {
                set_last_error("Invalid UTF-8 in path".to_string());
                return ptr::null_mut();
            }
        }
    };

    let runtime = match tokio::runtime::Runtime::new() {
        Ok(rt) => rt,
        Err(e) => {
            set_last_error(format!("Failed to create runtime: {}", e));
            return ptr::null_mut();
        }
    };

    let result = runtime.block_on(async { crate::from_config_file(path_str) });

    match result {
        Ok(analyzer) => {
            let internal = Box::new(AnalyzerInternal { analyzer, runtime });
            Box::into_raw(internal) as *mut CAnalyzer
        }
        Err(e) => {
            set_last_error(format!("{}", e));
            ptr::null_mut()
        }
    }
}