integer-result 1.0.0

Convert primitive and non-zero integer types to a Result
Documentation
  • Coverage
  • 100%
    5 out of 5 items documented3 out of 5 items with examples
  • Size
  • Source code size: 3.96 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 228.53 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • wasaylor/integer-result-rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • wasaylor

integer-result-rs

๐Ÿ”ขโœ…๐Ÿšซ

Using scalar types to indicate failure in Rust is discouraged, yet not uncommon in C. When calling C functions from Rust, you have to check return values that indicate success or failure like you would in C. This library adds methods to the primitive and non-zero integer types to ease the pain.

Now you can write this ๐Ÿงผ

use integer_result::Ext;

unsafe { some_c_function() }
  .ok_equal(0)
  .map_err(|val| YourRustyErrorType::from(val)) // or somethin' ..

Rather than this ๐Ÿคข

let val = unsafe { some_c_function() };

if val == 0 {
  Ok(())
} else {
  Err(YourRustyErrorType::from(val))
}