pub struct CString { priv buf: *c_char, priv owns_buffer_: bool, }
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.
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.
Any ownership of the buffer by the CString
wrapper is forgotten.
fn with_ref<T>(&self, f: &fn(*c_char) -> T) -> T
Calls a closure with a reference to the underlying *libc::c_char
.
Fails if the CString is null.
fn with_mut_ref<T>(&mut self, f: &fn(*mut c_char) -> T) -> T
Calls a closure with a mutable reference to the underlying *libc::c_char
.
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.
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 or is null.
fn iter<'a>(&'a self) -> CStringIterator<'a>
Return a CString iterator.
impl Drop for CString
fn drop(&mut self)
Prefix searches with a type followed by a colon (e.g.
fn:
) to restrict the search to a given type.
Accepted types are: fn
, mod
,
struct
(or str
), enum
,
trait
, typedef
(or
tdef
).