Macro c_str_macro::c_str [] [src]

macro_rules! c_str {
    ($lit:expr) => { ... };

Produce a CStr reference out of a static string literal.

This macro provides a convenient way to use string literals in expressions where a std::ffi::CStr reference is accepted. The macro parameter does not need to end with "\0", as the 0 byte is appended by the macro.

The lifetime of the output reference is inferred from the expansion site. This is always safe because the string is static and immutable.


extern crate c_str_macro;

extern crate libc;

fn main() {
    let s = c_str!("Hello, world!");
    unsafe { libc::puts(s.as_ptr()) };