os_essentials 0.0.3

A collection of tools for building simple educational operating systems in Rust in an x86 system. NOTE: MEANT TO BE BAREMETAL, YOU MUST HAVE compiler-buildtins-mem, core, compiler_builtins, alloc and a suited target, a vm or physical computer and a bootable usb required to test.
Documentation
#![no_std]

/// Converts a `u64` value to a string slice (`&'static str`).
///
/// This function converts a `u64` value into its string representation by repeatedly dividing the number by 10
/// to extract each digit. The result is stored in a static buffer, which is then used to return the string.
/// If the number is zero, it directly returns `"0"`.
///
/// # Example
/// 
/// ```rust
/// let value = 1234567890;
/// let result = uxstring(value);
/// assert_eq!(result, "1234567890");
/// ```
/// 
/// # Errors
/// 
/// This function does not return errors. It always successfully returns a string representation of the value.
/// 
/// # Safety
/// This function uses `unsafe` to directly manipulate the buffer and perform pointer operations.
/// Care should be taken not to invoke undefined behavior.
pub fn uxstring(value: u64) -> &'static str {
    static mut BUFFER: [u8; 20] = [0; 20]; // Static buffer to store string representation

    let mut idx = 19; // Start at the end of the buffer
    let mut num = value;

    // Handle the case where the number is zero
    if num == 0 {
        unsafe {
            BUFFER[idx] = b'0';
            return core::str::from_utf8_unchecked(&BUFFER[idx..]); // Return "0"
        }
    }

    // Convert the number to its string representation by extracting digits
    while num > 0 {
        let digit = (num % 10) as u8; // Extract the last digit
        unsafe {
            BUFFER[idx] = b'0' + digit; // Store the digit in the buffer
        }
        idx -= 1; // Move to the next position in the buffer
        num /= 10; // Remove the last digit from the number
    }

    let start_idx = idx + 1; // The index where the string representation starts
    let length = 20 - start_idx; // The length of the string

    // Copy the digits into the beginning of the buffer
    unsafe {
        core::ptr::copy_nonoverlapping(&BUFFER[start_idx], &mut BUFFER[0], length);
        BUFFER[length] = b'\0'; // Null-terminate the string
        core::str::from_utf8_unchecked(&BUFFER[..length]) // Return the string
    }
}