Struct rustrt::c_str::CString[src]

pub struct CString {
    // some fields omitted
}

The representation of a C String.

This structure wraps a *libc::c_char, and will automatically free the memory it is pointing to when it goes out of scope.

Methods

impl CString

unsafe fn new(buf: *c_char, owns_buffer: bool) -> CString

Create a C String from a pointer.

unsafe fn unwrap(self) -> *c_char

Unwraps the wrapped *libc::c_char from the CString wrapper.

The original object is destructed after this method is called, and if the underlying pointer was previously allocated, care must be taken to ensure that it is deallocated properly.

fn with_ref<T>(&self, f: |*c_char| -> T) -> T

Calls a closure with a reference to the underlying *libc::c_char.

Failure

Fails if the CString is null.

fn with_mut_ref<T>(&mut self, f: |*mut c_char| -> T) -> T

Calls a closure with a mutable reference to the underlying *libc::c_char.

Failure

Fails if the CString is null.

fn is_null(&self) -> bool

Returns true if the CString is a null.

fn is_not_null(&self) -> bool

Returns true if the CString is not null.

fn owns_buffer(&self) -> bool

Returns whether or not the CString owns the buffer.

fn as_bytes<'a>(&'a self) -> &'a [u8]

Converts the CString into a &[u8] without copying. Includes the terminating NUL byte.

Failure

Fails if the CString is null.

fn as_bytes_no_nul<'a>(&'a self) -> &'a [u8]

Converts the CString into a &[u8] without copying. Does not include the terminating NUL byte.

Failure

Fails if the CString is null.

fn as_str<'a>(&'a self) -> Option<&'a str>

Converts the CString into a &str without copying. Returns None if the CString is not UTF-8.

Failure

Fails if the CString is null.

fn iter<'a>(&'a self) -> CChars<'a>

Return a CString iterator.

Failure

Fails if the CString is null.

Trait Implementations

impl Clone for CString

fn clone(&self) -> CString

Clone this CString into a new, uniquely owned CString. For safety reasons, this is always a deep clone, rather than the usual shallow clone.

fn clone_from(&mut self, source: &Self)

impl PartialEq for CString

fn eq(&self, other: &CString) -> bool

fn ne(&self, other: &Self) -> bool

impl Drop for CString

fn drop(&mut self)

impl Collection for CString

fn len(&self) -> uint

Return the number of bytes in the CString (not including the NUL terminator).

Failure

Fails if the CString is null.

fn is_empty(&self) -> bool