#[allow(unused_macros)]
#[macro_export]
macro_rules! zstr {
($str:literal) => {{
assert!(
!$str.bytes().any(|b| b == b'\0'),
"zstr argument contains embedded NUL bytes",
);
#[allow(unsafe_code)]
unsafe {
$crate::ffi::ZStr::from_bytes_with_nul_unchecked(concat!($str, "\0").as_bytes())
}
}};
}
#[test]
fn test_zstr() {
use crate::ffi::ZString;
use alloc::borrow::ToOwned;
assert_eq!(zstr!(""), &*ZString::new("").unwrap());
assert_eq!(zstr!("").to_owned(), ZString::new("").unwrap());
assert_eq!(zstr!("hello"), &*ZString::new("hello").unwrap());
assert_eq!(zstr!("hello").to_owned(), ZString::new("hello").unwrap());
}
#[test]
#[should_panic]
fn test_invalid_zstr() {
let _ = zstr!("hello\0world");
}