1use std::{ffi::CString, fmt::Debug}; 2 3use anyhow::{anyhow, Context, Result}; 4 5pub fn cstring<T: AsRef<[u8]> + Debug>(s: T) -> Result<CString> { 6 CString::new(s.as_ref()).with_context(|| anyhow!("converting string-like to C string: {s:?}")) 7}