Struct std::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: *i8, owns_buffer: bool) -> CString
Create a C String from a pointer.
unsafe fn unwrap(self) -> *i8
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: |*i8| -> 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 i8| -> 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 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 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 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 self) -> CChars<'a>
Trait Implementations
impl BytesContainer for CString
fn container_as_bytes<'a>(&'a self) -> &'a [u8]
fn container_into_owned_bytes(self) -> Vec<u8>
fn container_as_str<'a>(&'a self) -> Option<&'a str>
fn is_str(_: Option<Self>) -> bool
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.