mu_lib 0.2.2

XCENA mu Library
Documentation
//! Assertion module providing condition checking functionality
//!
//! This module provides functions for condition checking and program termination.

#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

pub use crate::bindings::root::{exitRB, AssertRB};

/// Function to check a condition and terminate the program if it fails
///
/// # Arguments
/// * `cond` - The condition to check
///
/// # Examples
/// ```
/// use mu_lib::assert::assert;
///
/// assert!(1 + 1 == 2);
/// ```
#[track_caller]
pub fn assert(cond: bool) {
    let location = core::panic::Location::caller();
    let file = location.file().as_ptr() as *const core::ffi::c_char;
    let function = b"unknown\0".as_ptr() as *const core::ffi::c_char;
    let line = location.line() as i32;

    unsafe { AssertRB(cond, file, function, line) }
}

/// Function to immediately terminate the program
///
/// # Examples
/// ```
/// use mu_lib::assert::exit;
///
/// exit();
/// ```
pub fn exit() {
    unsafe { exitRB() }
}