Trait std::c_str::ToCStr

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.

Required Methods

fn to_c_str(&self) -> CString

Copy the receiver into a CString.

Failure

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.

Provided Methods

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.

Example

let s = "PATH".with_c_str(|path| libc::getenv(path))

Failure

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.

Implementors