Trait 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, F>(&self, f: F) -> T
    where
        F: FnOnce(*const c_char) -> T
, { ... }
unsafe fn with_c_str_unchecked<T, F>(&self, f: F) -> T
    where
        F: FnOnce(*const c_char) -> T
, { ... } }

A generic trait for converting a value to a CString.

Required Methods

Copy the receiver into a CString.

Panics

Panics the task if the receiver has an interior null.

Unsafe variant of to_c_str() that doesn't check for nulls.

Provided Methods

Work with a temporary CString constructed from the receiver. The provided *libc::c_char will be freed immediately upon return.

Example

extern crate libc;

use std::c_str::ToCStr;

fn main() {
    let s = "PATH".with_c_str(|path| unsafe {
        libc::getenv(path)
    });
}

Panics

Panics the task if the receiver has an interior null.

Unsafe variant of with_c_str() that doesn't check for nulls.

Implementations on Foreign Types

impl ToCStr for str
[src]

[src]

[src]

[src]

[src]

impl ToCStr for String
[src]

[src]

[src]

[src]

[src]

impl ToCStr for [u8]
[src]

[src]

[src]

[src]

[src]

impl<'a, T: ToCStr> ToCStr for &'a T
[src]

[src]

[src]

[src]

[src]

Implementors