Macro rglua::try_cstr [−][src]
macro_rules! try_cstr {
($rstring : literal) => { ... };
($rstring : expr) => { ... };
}Expand description
Tries to create a *const i8 from a &str This either takes a literal and appends a null char (\0) to it. or if it is a value, makes a cstring and returns the pointer to it.
Examples
ⓘ
use rglua::prelude::*;
let a = b"Hello world!".as_ptr() as *const i8;
let b = try_cstr!("Hello world!");
unsafe { assert_eq!(*a, *b) } ;
let c = "Invalid! 👎 \0"; // Cannot have nulls inside of it.
let d = try_cstr!(c).unwrap();