1
2
3
4
5
6
7
8
9
10
11
12
//! Utilities for dealing with string conversion.

use alloc::ffi::CString;

use core::fmt::Debug;

#[inline(always)]
/// Converts a Rust String to a CString.
pub fn str_to_cstring<S: AsRef<str> + Debug>(s: S) -> CString {
    CString::new(s.as_ref())
        .unwrap_or_else(|_| panic!("Was unable to convert {:?} to CString.", s.as_ref()))
}