macro_rules! c_str {
($str:expr) => { ... };
}Expand description
Creates a new CStr at compile time.
Rust supports C string literals since Rust 1.77, and they should be used instead of this macro where possible. This macro exists to allow static non-literal C strings to be created at compile time. This is most often used in other macros.
§Panics
This macro panics if the operand contains an interior NUL byte.
§Examples
// This is allowed, but `c"literal"` should be preferred for literals.
const BAD: &CStr = c_str!("literal");
// `c_str!` is still needed for static non-literal C strings.
const GOOD: &CStr = c_str!(concat!(file!(), ":", line!(), ": My CStr!"));