xplane11-sys

git clone git://archive.git.mtrnord.blog/MTRNord/xplane11-sys.git
Log | Files | Refs | README | LICENSE

utils.rs (1166B)


      1 pub mod log {
      2     #[allow(unused_macros)]
      3     #[macro_export]
      4     macro_rules! info {
      5         () => (
      6             unsafe {
      7                 XPLMDebugString(
      8                     CString::new("\n")
      9                         .expect("CString::new failed")
     10                         .as_ptr(),
     11                 );
     12             }
     13         );
     14         ($fmt:expr) => {
     15             unsafe {
     16                 XPLMDebugString(
     17                     CString::new(format!($fmt))
     18                         .expect("CString::new failed")
     19                         .as_ptr(),
     20                 );
     21             }
     22         };
     23         ($fmt:expr, $($args:tt)*) => {
     24             unsafe {
     25                 XPLMDebugString(
     26                     CString::new(format!($fmt, $( $args ),*))
     27                         .expect("CString::new failed")
     28                         .as_ptr(),
     29                 );
     30             }
     31         }
     32     }
     33 }
     34 
     35 use std::ffi::CString;
     36 pub fn write_c_char(string: &str, ptr: *mut ::std::os::raw::c_char) -> anyhow::Result<()> {
     37     let c_str = CString::new(string)?;
     38     unsafe {
     39         std::ptr::copy_nonoverlapping(c_str.as_ptr(), ptr, c_str.as_bytes_with_nul().len());
     40     }
     41     Ok(())
     42 }