byte-strings-rs

Rust byte strings manipulation, for a better and safer C FFI

Repository Latest version Documentation License

Example

Featuring the c_str! macro to create valid C string literals with no runtime cost!

```rust mod puts { use ::std::{ ffi::CStr, os::raw::{cchar, cint}, };

/// C FFI
extern "C" { fn puts (message: *const c_char) -> c_int; }

/// Safe wrapper around C FFI
pub fn safe (message: &'_ CStr) -> i32
{
    unsafe {
        puts(message.as_ptr()) as i32
    }
}

} use self::puts::safe as safe_puts;

fn main () { use ::bytestrings::cstr;

safe_puts(
    c_str!( // Simple and safe!
        "Hello, ",
        "World!",
    ) // No runtime error nor runtime cost!
);

} ```