to_cstring

Macro to_cstring 

Source
macro_rules! to_cstring {
    ($s:expr) => { ... };
}
Expand description

Converts a Rust string to a CString with error handling.

This macro creates a CString from a Rust string reference, returning a Result that can be used with the ? operator. If the conversion fails (e.g., due to interior null bytes), it returns an appropriate error.

§Returns

  • Ok(CString) - On successful conversion
  • Err(Error::Unhandled) - If the string contains interior null bytes

§Examples

use osal_rs::to_cstring;
use osal_rs::utils::Result;
 
fn pass_to_c_api(name: &str) -> Result<()> {
    let c_name = to_cstring!(name)?;
    // Use c_name.as_ptr() with C FFI
    Ok(())
}