Trait rustrt::c_str::ToCStr[src]
pub trait ToCStr {
fn to_c_str(&self) -> CString;
unsafe fn to_c_str_unchecked(&self) -> CString;
fn with_c_str<T>(&self, f: |*c_char| -> T) -> T { ... }
unsafe fn with_c_str_unchecked<T>(&self, f: |*c_char| -> T) -> T { ... }
}A generic trait for converting a value to a CString.
Required Methods
fn to_c_str(&self) -> CString
unsafe fn to_c_str_unchecked(&self) -> CString
Unsafe variant of to_c_str() that doesn't check for nulls.
Provided Methods
fn with_c_str<T>(&self, f: |*c_char| -> T) -> T
Work with a temporary CString constructed from the receiver.
The provided *libc::c_char will be freed immediately upon return.
Example
extern crate libc; fn main() { let s = "PATH".with_c_str(|path| unsafe { libc::getenv(path) }); }
Failure
Fails the task if the receiver has an interior null.
unsafe fn with_c_str_unchecked<T>(&self, f: |*c_char| -> T) -> T
Unsafe variant of with_c_str() that doesn't check for nulls.