pub trait ToCStr { fn to_c_str(&self) -> CString; unsafe fn to_c_str_unchecked(&self) -> CString; fn with_c_str<T>(&self, f: &fn(*c_char) -> T) -> T { ... } unsafe fn with_c_str_unchecked<T>(&self, f: &fn(*c_char) -> T) -> T { ... } }
A generic trait for converting a value to a CString.
fn to_c_str(&self) -> CString
Copy the receiver into a CString.
Raises the null_byte
condition if the receiver has an interior null.
unsafe fn to_c_str_unchecked(&self) -> CString
Unsafe variant of to_c_str()
that doesn't check for nulls.
fn with_c_str<T>(&self, f: &fn(*c_char) -> T) -> T
Work with a temporary CString constructed from the receiver.
The provided *libc::c_char
will be freed immediately upon return.
let s = "PATH".with_c_str(|path| libc::getenv(path))
Raises the null_byte
condition if the receiver has an interior null.
unsafe fn with_c_str_unchecked<T>(&self, f: &fn(*c_char) -> T) -> T
Unsafe variant of with_c_str()
that doesn't check for nulls.
WindowsPath
PosixPath
impl<'self> ToCStr for &'self str
impl<'self> ToCStr for &'self [u8]
Prefix searches with a type followed by a colon (e.g.
fn:
) to restrict the search to a given type.
Accepted types are: fn
, mod
,
struct
(or str
), enum
,
trait
, typedef
(or
tdef
).