mod safe {
use ::std::{
ffi::CStr,
os::raw::{c_char, c_int},
};
mod ffi { use super::*; pub unsafe extern "C"
fn puts (_: *const c_char) -> c_int { 0 }
}
pub fn puts (message: &'_ CStr) -> i32
{
unsafe {
ffi::puts(message.as_ptr()) as i32
}
}
}
fn main ()
{
use ::byte_strings::c_str;
dbg!(safe::puts(
c_str!(
"Hello, ",
"World!",
) ));
}
#[test]
fn main_simple_and_safe ()
{
use ::byte_strings::c_str;
safe::puts(
c_str!(
"Hello, ",
"World!",
) );
}
#[test]
fn main_no_c_str_macro ()
{
use ::std::ffi::CString;
safe::puts(
&CString::new( concat!(
"Hello, ",
"World!",
).as_bytes()
).unwrap()
);
}
#[test]
#[should_panic]
fn main_no_c_str_macro_2 ()
{
use ::std::ffi::CStr;
safe::puts(
CStr::from_bytes_with_nul( concat!(
"Hello, ",
"World!",
).as_bytes()
).unwrap()
);
}
#[test]
#[should_panic]
fn main_no_c_str_macro_bad_copy_paste ()
{
use ::std::ffi::CStr;
safe::puts(
CStr::from_bytes_with_nul( concat!(
"Hello,\0",
"World!\0",
).as_bytes()
).unwrap()
);
}