Crate nopanick

source ·
Expand description

nopanick-rs (No Panic!)

No panic library for add, sub, mul, div operators in Rust.

Generates less instructions, suite for barematal or embedded system.

Example#1

use nopanick::*;

fn main() {
    unsafe {
        println!("{}", div!(sub!(add!(100i32, 10i32), 5i32), 5i32));
    }
}

Example#2

How to use .unwarp_nop() with Option<T>

use nopanick::*;

fn rem(a: u32, b: u32) -> Option<u32> {
    if b != 0 {
        Some(a % b)
    } else {
        None
    }
}

fn main() {
    let a = 4u32;
    let b = 3u32;
    let r = unsafe { rem(a, b).unwrap_nop() };

    println!("{} % {} ={}", a, b, r);
}

Example#3

If None was unwraped, UB occurs.

use nopanick::*;

fn rem(a: u32, b: u32) -> Option<u32> {
    if b != 0 {
        Some(a % b)
    } else {
        None
    }
}

fn main() {
    let a = 4u32;
    let b = 0u32;
    let r = unsafe { rem(a, b).unwrap_nop() };

    println!("{} % {} ={}", a, b, r);
}
//error: process didn't exit successfully: `target\debug\examples\option.exe` (exit code: 0xc000001d, STATUS_ILLEGAL_INSTRUCTION) Illegal instruction

Macros

Traits

  • This trait provides unsafe fn unwrap_nop(self) -> Self::Output for Option<T> and Result<T,E>

Functions