waddling-errors 0.7.3

Structured, secure-by-default diagnostic codes for distributed systems with no_std and role-based documentation
Documentation
//! Minimal WASM example to test production size
//! Build: cargo build --example wasm_minimal --target wasm32-unknown-unknown --release --no-default-features

use waddling_errors::{Code, ComponentId, PrimaryId, error};

#[derive(Debug, Copy, Clone)]
enum Component {
    Auth,
}

impl ComponentId for Component {
    fn as_str(&self) -> &'static str {
        "AUTH"
    }
}

#[derive(Debug, Copy, Clone)]
enum Primary {
    Token,
}

impl PrimaryId for Primary {
    fn as_str(&self) -> &'static str {
        "TOKEN"
    }
}

const ERR_TOKEN_MISSING: Code<Component, Primary> = error(Component::Auth, Primary::Token, 1);

// For WASM testing - export functions
#[cfg(target_arch = "wasm32")]
#[unsafe(no_mangle)]
pub extern "C" fn get_severity_char() -> u8 {
    ERR_TOKEN_MISSING.severity().as_char() as u8
}

// For regular builds - just print
fn main() {
    println!("Error code: {}", ERR_TOKEN_MISSING.code());
    println!("Severity: {}", ERR_TOKEN_MISSING.severity().as_char());
    println!("\nThis is a minimal example for WASM size testing.");
    println!("To build for WASM:");
    println!(
        "  cargo build --example wasm_minimal --target wasm32-unknown-unknown --release --no-default-features"
    );
}