Skip to content

Convert primitive and non-zero integer types to a Result

Notifications You must be signed in to change notification settings

wasaylor/integer-result-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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))
}

About

Convert primitive and non-zero integer types to a Result

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages