pub trait ToCString {
// Required method
fn into_cstr<'a>(self) -> Cow<'a, CStr>
where Self: 'a;
}
Expand description
Represents any type that can be represented as a C String. You shouldn’t
need to implement this yourself as the most commonly used string
-y types
already have this implemented.
§Examples
use std::ffi::{CString, CStr};
use std::borrow::Cow;
use zsh_module::ToCString;
let cstr = CStr::from_bytes_with_nul(b"Hello, world!\0").unwrap();
let cstring = CString::new("Hello, world!").unwrap();
assert!(matches!(cstr.into_cstr(), Cow::Borrowed(data) if data == cstr));
let string = "Hello, world!";
assert!(matches!(ToCString::into_cstr(string), Cow::Owned(cstring)));