byte-strings-rs
Rust byte strings manipulation, for a better and safer C FFI
Example
Featuring the c_str!
macro to create valid C string literals with no
runtime cost!
use safe as safe_puts;
Rust byte strings manipulation, for a better and safer C FFI
Featuring the c_str!
macro to create valid C string literals with no
runtime cost!
mod puts {
use ::std::{
ffi::CStr,
os::raw::{c_char, c_int},
};
/// 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 ::byte_strings::c_str;
safe_puts(
c_str!( // Simple and safe!
"Hello, ",
"World!",
) // No runtime error nor runtime cost!
);
}