Crate lx

source ·
Expand description

A no_std interface to the userspace Linux ABI designed to have no overhead, but still be safe when possible by leveraging Rust’s type system.

Result overhead

Although types like Result<(), i32> are sometimes used in place of the smaller i32 which can both represent errors and values on success, it doesn’t add memory overhead or register pressure in practice because functions are inlined.

To verify this, try to look at the assembler generated by this code when optimizations are enabled:

extern "C" {
    fn fallible() -> i32;

    fn test_succeeded();
    fn test_failed(err: i32);
}

fn fallible_safe() -> Result<(), i32> {
    let ret = unsafe { fallible() };
    if ret < 0 { return Err(ret); }
    Ok(())
}

pub fn test() {
    if let Err(e) = fallible_safe() {
        unsafe { test_failed(e) };
        return;
    }
    unsafe { test_succeeded() };
}

Modules

Macros

Structs

Enums

Constants

Traits

Functions

Type Aliases