use std::ffi::c_char;
pub(crate) fn str_to_raw<S: AsRef<str>>(s: S) -> *mut c_char {
try_ptr_from_str!(s.as_ref())
}
macro_rules! iter_to_array {
( $iter:expr, $func:expr ) => {{
let mut ptrs: Vec<_> = $iter.map(|o| $func(o)).collect();
ptrs.push(std::ptr::null_mut());
ptrs.shrink_to_fit();
ptrs
}};
}
pub(crate) use iter_to_array;
macro_rules! try_ptr_from_str {
( $s:expr ) => {{
match std::ffi::CString::new($s) {
Ok(s) => s.into_raw(),
Err(e) => panic!("{e}"),
}
}};
}
pub(crate) use try_ptr_from_str;