[−][src]Crate byte_strings
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!
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! ); }
Macros
as_bytes | Evaluates the input string literal as a byte string literal. |
c_str | Converts into a valid C string at compile time (no runtime cost) |
concat_bytes | Concatenates byte string literals into a single byte string literal |