u32err

Crates.iou32err
lib.rsu32err
version0.1.1
sourcesrc
created_at2022-12-03 18:40:11.181995
updated_at2022-12-03 19:06:42.14377
descriptionA neat error type for FFI functions (where non-zero = failure)
homepagehttps://github.com/Wazzaps/u32err/
repositoryhttps://github.com/Wazzaps/u32err/
max_upload_size
id729206
size6,243
Wazzaps (Wazzaps)

documentation

README

u32err

This crate implements the core::ops::Try trait with a thin wrapper over u32.

You may use it to implement ergonomic error handling for FFI functions that return non-zero values on failure, or as a lightweight Result.

Example

use u32err::ErrCode;
extern "C" {
    /// This is a function that does something (via FFI).
    ///
    /// It returns either a 0 on success, or a non-zero number on failure.
    /// The real FFI signature of this function returns [`u32`], but the types are compatible.
    fn returns_zero_on_success() -> ErrCode;
}

fn foo() -> ErrCode {
    unsafe {
        returns_zero_on_success()?;
    }
    ErrCode(0)
}
Commit count: 2

cargo fmt