Macro rglua::cstr[][src]

macro_rules! cstr {
    ($rstring : literal) => { ... };
    ($rstring : expr) => { ... };
}
Expand description

Creates *const i8 from a &str This either takes a literal and appends a null char (\0) to it. or if it is an expression, tries to make a CString from it. Will panic if passed an expression that a CString could not be created from.

Examples

use rglua::prelude::*;
let a = b"Hello world!".as_ptr() as *const i8;
let b = cstr!("Hello world!");
unsafe { assert_eq!(*a, *b) };

let c = "Hello world!";
let d = cstr!(c); // Macro doesn't know this is a literal, so it will try to make a CString
unsafe { assert_eq!(*b, *d.as_ptr()) };