1 /// This macro creates a zero-overhead &CStr by adding a NUL terminator to
2 /// the string literal passed into it at compile-time. Use it like:
5 /// let some_const_cstr = const_cstr!("abc");
8 /// The above is roughly equivalent to:
11 /// let some_const_cstr = CStr::from_bytes_with_nul(b"abc\0").unwrap()
14 /// Note that macro only checks the string literal for internal NULs if
15 /// debug-assertions are enabled in order to avoid runtime overhead in release
18 macro_rules
! const_cstr
{
22 let str_plus_nul
= concat
!($s
, "\0");
24 if cfg
!(debug_assertions
) {
25 CStr
::from_bytes_with_nul(str_plus_nul
.as_bytes()).unwrap()
27 unsafe { CStr::from_bytes_with_nul_unchecked(str_plus_nul.as_bytes()) }