cstr!() { /* proc-macro */ }Expand description
cstr checks its input for null bytes and, if none are found, generates an &'static CStr. It must be provided a string literal.
§Examples
use std::ffi::CStr;
use constant_cstr::cstr;
const DEV_PTMX: &'static CStr = cstr!("/dev/ptmx");Passing an input string with a null byte will cause a compile error with a message indicating the position of the null byte:
ⓘ
use std::ffi::CStr;
use constant_cstr::cstr;
const HELLO: &'static CStr = cstr!("Hell\0, world");error: proc macro panicked
--> src/example.rs:4:34
|
4 | const HELLO: &'static CStr = cstr!("Hell\0, world");
| ^^^^^^^^^^^^^^^^^^^^^^
|
= help: message: "Hell\0, world" contains a null byte at position 4