A wrapper for a null-terminated (C) string.
Allocates memory for the string on the heap, so it must be freed.
Example
use std::ffi::CString;
let s = CString::from_slice("Hello, world!");
defer s.free();
libc::puts(s.ptr);
Run this example
Fields
-
ptr: &c_char
Methods
impl CString { ... }
-
Create a new CString from a string slice
Allocates memory.
-
fn from_raw(ptr: &c_char) -> CString
Create a CString from a raw pointer to a null-terminated string.
-
fn null() -> CString
A null C string.
-
Returns the length of the string.
-
fn free(self: &mut CString)
Frees the memory backing the object.
-
Returns a copy of the object.