Rust Search

Find the best content on Rust, curated by the community; a search engine for Rustaceans.
doc.rust-lang.org
pub struct CString
A type representing an owned, C-compatible, nul-terminated string with no nul bytes in the middle.
struct alloc Stable since 1.64.0 Version 1.100.0-nightly
doc.rust-lang.org
pub fn as_bytes(&self) -> &[u8]
Returns the contents of this CString as a slice of bytes.
method alloc Stable since 1.0.0 Version 1.100.0-nightly
doc.rust-lang.org
pub fn as_bytes_with_nul(&self) -> &[u8]
Equivalent to CString::as_bytes() except that the returned slice includes the trailing nul terminator.
method alloc Stable since 1.0.0 Version 1.100.0-nightly
doc.rust-lang.org
pub fn as_c_str(&self) -> &CStr
Extracts a CStr slice containing the entire string.
method alloc Stable since 1.20.0 Version 1.100.0-nightly
doc.rust-lang.org
pub unsafe fn from_raw(ptr: *mut c_char) -> CString
Retakes ownership of a CString that was transferred to C via CString::into_raw.
associated_function alloc Stable since 1.4.0 Version 1.100.0-nightly
doc.rust-lang.org
pub unsafe fn from_vec_unchecked(v: Vec<u8>) -> Self
Creates a C-compatible string by consuming a byte vector, without checking for interior 0 bytes.
associated_function alloc Stable since 1.0.0 Version 1.100.0-nightly
doc.rust-lang.org
pub fn from_vec_with_nul(v: Vec<u8>) -> Result<Self, FromVecWithNulError>
Attempts to convert a Vec<u8> to a CString.
associated_function alloc Stable since 1.58.0 Version 1.100.0-nightly
doc.rust-lang.org
pub unsafe fn from_vec_with_nul_unchecked(v: Vec<u8>) -> Self
Converts a Vec<u8> to a CString without checking the invariants on the given Vec.
associated_function alloc Stable since 1.58.0 Version 1.100.0-nightly
doc.rust-lang.org
pub fn into_boxed_c_str(self) -> Box<CStr>
Converts this CString into a boxed CStr.
method alloc Stable since 1.20.0 Version 1.100.0-nightly
doc.rust-lang.org
pub fn into_bytes(self) -> Vec<u8>
Consumes the CString and returns the underlying byte buffer.
method alloc Stable since 1.7.0 Version 1.100.0-nightly
doc.rust-lang.org
pub fn into_bytes_with_nul(self) -> Vec<u8>
Equivalent to CString::into_bytes() except that the returned vector includes the trailing nul terminator.
method alloc Stable since 1.7.0 Version 1.100.0-nightly
doc.rust-lang.org
pub fn into_raw(self) -> *mut c_char
Consumes the CString and transfers ownership of the string to a C caller.
method alloc Stable since 1.4.0 Version 1.100.0-nightly
doc.rust-lang.org
pub fn into_string(self) -> Result<String, IntoStringError>
Converts the CString into a String if it contains valid UTF-8 data.
method alloc Stable since 1.7.0 Version 1.100.0-nightly
doc.rust-lang.org
pub fn new<T>(t: T) -> Result<CString, NulError>
Creates a new C-compatible string from a container of bytes.
associated_function alloc Stable since 1.0.0 Version 1.100.0-nightly
doc.rust-lang.org
pub struct FromVecWithNulError
An error indicating that a nul byte was not in the expected position.
struct alloc Stable since 1.64.0 Version 1.100.0-nightly
doc.rust-lang.org
pub fn as_bytes(&self) -> &[u8]
Returns a slice of u8s bytes that were attempted to convert to a CString.
method alloc Stable since 1.58.0 Version 1.100.0-nightly
doc.rust-lang.org
pub fn into_bytes(self) -> Vec<u8>
Returns the bytes that were attempted to convert to a CString.
method alloc Stable since 1.58.0 Version 1.100.0-nightly
doc.rust-lang.org
pub struct IntoStringError
An error indicating invalid UTF-8 when converting a CString into a String.
struct alloc Stable since 1.64.0 Version 1.100.0-nightly
doc.rust-lang.org
pub fn into_cstring(self) -> CString
Consumes this error, returning original CString which generated the error.
method alloc Stable since 1.7.0 Version 1.100.0-nightly
doc.rust-lang.org
pub fn utf8_error(&self) -> Utf8Error
Access the underlying UTF-8 error that was the cause of this error.
method alloc Stable since 1.7.0 Version 1.100.0-nightly
"In #rustlang, None is always an Option<\_>."

Search tips

Type anything to search across articles, videos (including conference talks), podcasts, research, crates, and Rust API documentation. These operators give you finer control — click an example to try it.

Find pages containing all your words. Pages where the words appear together rank higher.
Quote part of your query to keep those words together as an exact phrase within a larger search.
Wrap the whole query in quotes for a verbatim search that matches text exactly, punctuation and all — perfect for Rust syntax. Needs at least 3 characters.
Put ! first to open the top result immediately. Quote the whole query for a literal leading bang, as in '!Send'. Bangs elsewhere, such as println!, stay literal. Browser and launcher shortcuts can invoke this directly. See search integrations.
Limit results to a single site. Works on its own () too. One site: per search.

Use the tabs and filters above the results to narrow by content type, publication year, and sort order.