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 instructionMacros§
Traits§
- Nop
- This trait provides
unsafe fn unwrap_nop(self) -> Self::OutputforOption<T>andResult<T,E>
Functions§
- unwrap_
option ⚠ - Function like .unwrap_unchecked() for
Option<T> - unwrap_
result ⚠ - Function like .unwrap_unchecked() for
Result<T,E>