ssw/doc/rustix/ffi/struct.CString.html
2023-01-09 19:23:20 +01:00

375 lines
118 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A type representing an owned, C-compatible, nul-terminated string with no nul bytes in the middle."><meta name="keywords" content="rust, rustlang, rust-lang, CString"><title>CString in rustix::ffi - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled><link rel="stylesheet" type="text/css" href="../../dark.css" disabled><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../main.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../favicon.svg"></head><body class="rustdoc struct"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../../rustix/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2 class="location"></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../rustix/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">CString</a></h2><div class="sidebar-elems"><section><div class="block"><h3 class="sidebar-title"><a href="#implementations">Methods</a></h3><ul><li><a href="#method.as_bytes">as_bytes</a></li><li><a href="#method.as_bytes_with_nul">as_bytes_with_nul</a></li><li><a href="#method.as_c_str">as_c_str</a></li><li><a href="#method.from_raw">from_raw</a></li><li><a href="#method.from_vec_unchecked">from_vec_unchecked</a></li><li><a href="#method.from_vec_with_nul">from_vec_with_nul</a></li><li><a href="#method.from_vec_with_nul_unchecked">from_vec_with_nul_unchecked</a></li><li><a href="#method.into_boxed_c_str">into_boxed_c_str</a></li><li><a href="#method.into_bytes">into_bytes</a></li><li><a href="#method.into_bytes_with_nul">into_bytes_with_nul</a></li><li><a href="#method.into_raw">into_raw</a></li><li><a href="#method.into_string">into_string</a></li><li><a href="#method.new">new</a></li></ul></div><div class="block"><h3 class="sidebar-title"><a href="#deref-methods-CStr">Methods from Deref&lt;Target=CStr&gt;</a></h3><ul><li><a href="#method.as_ptr">as_ptr</a></li><li><a href="#method.to_bytes">to_bytes</a></li><li><a href="#method.to_bytes_with_nul">to_bytes_with_nul</a></li><li><a href="#method.to_str">to_str</a></li></ul></div><div class="block"><h3 class="sidebar-title"><a href="#trait-implementations">Trait Implementations</a></h3><ul><li><a href="#impl-AsRef%3CCStr%3E-for-CString">AsRef&lt;CStr&gt;</a></li><li><a href="#impl-Borrow%3CCStr%3E-for-CString">Borrow&lt;CStr&gt;</a></li><li><a href="#impl-Clone-for-CString">Clone</a></li><li><a href="#impl-Debug-for-CString">Debug</a></li><li><a href="#impl-Default-for-CString">Default</a></li><li><a href="#impl-Deref-for-CString">Deref</a></li><li><a href="#impl-Drop-for-CString">Drop</a></li><li><a href="#impl-Eq-for-CString">Eq</a></li><li><a href="#impl-From%3C%26CStr%3E-for-CString">From&lt;&amp;CStr&gt;</a></li><li><a href="#impl-From%3CBox%3CCStr%2C%20Global%3E%3E-for-CString">From&lt;Box&lt;CStr, Global&gt;&gt;</a></li><li><a href="#impl-From%3CCow%3C%27a%2C%20CStr%3E%3E-for-CString">From&lt;Cow&lt;&#39;a, CStr&gt;&gt;</a></li><li><a href="#impl-From%3CVec%3CNonZeroU8%2C%20Global%3E%3E-for-CString">From&lt;Vec&lt;NonZeroU8, Global&gt;&gt;</a></li><li><a href="#impl-Hash-for-CString">Hash</a></li><li><a href="#impl-Index%3CRangeFull%3E-for-CString">Index&lt;RangeFull&gt;</a></li><li><a href="#impl-Ord-for-CString">Ord</a></li><li><a href="#impl-PartialEq%3CCString%3E-for-CString">PartialEq&lt;CString&gt;</a></li><li><a href="#impl-PartialOrd%3CCString%3E-for-CString">PartialOrd&lt;CString&gt;</a></li><li><a href="#impl-StructuralEq-for-CString">StructuralEq</a></li><li><a href="#impl-StructuralPartialEq-for-CString">StructuralPartialEq</a></li></ul></div><div class="block"><h3 class="sidebar-title"><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul><li><a href="#impl-RefUnwindSafe-for-CString">RefUnwindSafe</a></li><li><a href="#impl-Send-for-CString">Send</a></li><li><a href="#impl-Sync-for-CString">Sync</a></li><li><a href="#impl-Unpin-for-CString">Unpin</a></li><li><a href="#impl-UnwindSafe-for-CString">UnwindSafe</a></li></ul></div><div class="block"><h3 class="sidebar-title"><a href="#blanket-implementations">Blanket Implementations</a></h3><ul><li><a href="#impl-Any-for-CString">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-CString">Borrow&lt;T&gt;</a></li><li><a href="#impl-BorrowMut%3CT%3E-for-CString">BorrowMut&lt;T&gt;</a></li><li><a href="#impl-From%3CT%3E-for-CString">From&lt;T&gt;</a></li><li><a href="#impl-Into%3CU%3E-for-CString">Into&lt;U&gt;</a></li><li><a href="#impl-ToOwned-for-CString">ToOwned</a></li><li><a href="#impl-TryFrom%3CU%3E-for-CString">TryFrom&lt;U&gt;</a></li><li><a href="#impl-TryInto%3CU%3E-for-CString">TryInto&lt;U&gt;</a></li></ul></div></section><h2 class="location"><a href="index.html">In rustix::ffi</a></h2></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../rustix/index.html"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><button type="button">?</button></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></div></form></nav></div><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn"><span class="in-band">Struct <a href="../index.html">rustix</a>::<wbr><a href="index.html">ffi</a>::<wbr><a class="struct" href="#">CString</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><span class="since" title="Stable since Rust version 1.64.0">1.64.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#112">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="docblock item-decl"><pre class="rust struct"><code>pub struct CString { /* private fields */ }</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A type representing an owned, C-compatible, nul-terminated string with no nul bytes in the
middle.</p>
<p>This type serves the purpose of being able to safely generate a
C-compatible string from a Rust byte slice or vector. An instance of this
type is a static guarantee that the underlying bytes contain no interior 0
bytes (“nul characters”) and that the final byte is 0 (“nul terminator”).</p>
<p><code>CString</code> is to <code>&amp;<a href="struct.CStr.html" title="CStr">CStr</a></code> as <a href="https://doc.rust-lang.org/1.64.0/alloc/string/struct.String.html" title="String"><code>String</code></a> is to <code>&amp;<a href="https://doc.rust-lang.org/1.64.0/std/primitive.str.html" title="str">str</a></code>: the former
in each pair are owned strings; the latter are borrowed
references.</p>
<h2 id="creating-a-cstring"><a href="#creating-a-cstring">Creating a <code>CString</code></a></h2>
<p>A <code>CString</code> is created from either a byte slice or a byte vector,
or anything that implements <code><a href="https://doc.rust-lang.org/1.64.0/core/convert/trait.Into.html" title="Into">Into</a>&lt;<a href="https://doc.rust-lang.org/1.64.0/alloc/vec/struct.Vec.html" title="Vec">Vec</a>&lt;<a href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html" title="u8">u8</a>&gt;&gt;</code> (for
example, you can build a <code>CString</code> straight out of a <a href="https://doc.rust-lang.org/1.64.0/alloc/string/struct.String.html" title="String"><code>String</code></a> or
a <code>&amp;<a href="https://doc.rust-lang.org/1.64.0/std/primitive.str.html" title="str">str</a></code>, since both implement that trait).</p>
<p>The <a href="struct.CString.html#method.new" title="CString::new"><code>CString::new</code></a> method will actually check that the provided <code>&amp;[<a href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html" title="u8">u8</a>]</code>
does not have 0 bytes in the middle, and return an error if it
finds one.</p>
<h2 id="extracting-a-raw-pointer-to-the-whole-c-string"><a href="#extracting-a-raw-pointer-to-the-whole-c-string">Extracting a raw pointer to the whole C string</a></h2>
<p><code>CString</code> implements an <a href="struct.CStr.html#method.as_ptr" title="CStr::as_ptr"><code>as_ptr</code></a> method through the <a href="https://doc.rust-lang.org/1.64.0/core/ops/deref/trait.Deref.html"><code>Deref</code></a>
trait. This method will give you a <code>*const c_char</code> which you can
feed directly to extern functions that expect a nul-terminated
string, like Cs <code>strdup()</code>. Notice that <a href="struct.CStr.html#method.as_ptr" title="CStr::as_ptr"><code>as_ptr</code></a> returns a
read-only pointer; if the C code writes to it, that causes
undefined behavior.</p>
<h2 id="extracting-a-slice-of-the-whole-c-string"><a href="#extracting-a-slice-of-the-whole-c-string">Extracting a slice of the whole C string</a></h2>
<p>Alternatively, you can obtain a <code>&amp;[<a href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html" title="u8">u8</a>]</code> slice from a
<code>CString</code> with the <a href="struct.CString.html#method.as_bytes" title="CString::as_bytes"><code>CString::as_bytes</code></a> method. Slices produced in this
way do <em>not</em> contain the trailing nul terminator. This is useful
when you will be calling an extern function that takes a <code>*const u8</code> argument which is not necessarily nul-terminated, plus another
argument with the length of the string — like Cs <code>strndup()</code>.
You can of course get the slices length with its
<a href="https://doc.rust-lang.org/1.64.0/std/primitive.slice.html#method.len" title="slice::len"><code>len</code></a> method.</p>
<p>If you need a <code>&amp;[<a href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html" title="u8">u8</a>]</code> slice <em>with</em> the nul terminator, you
can use <a href="struct.CString.html#method.as_bytes_with_nul" title="CString::as_bytes_with_nul"><code>CString::as_bytes_with_nul</code></a> instead.</p>
<p>Once you have the kind of slice you need (with or without a nul
terminator), you can call the slices own
<a href="https://doc.rust-lang.org/1.64.0/std/primitive.slice.html#method.as_ptr" title="slice::as_ptr"><code>as_ptr</code></a> method to get a read-only raw pointer to pass to
extern functions. See the documentation for that function for a
discussion on ensuring the lifetime of the raw pointer.</p>
<h2 id="examples"><a href="#examples">Examples</a></h2>
<div class='information'><div class='tooltip ignore'></div></div><div class="example-wrap"><pre class="rust rust-example-rendered ignore"><code><span class="kw">use</span> <span class="ident">std::ffi::CString</span>;
<span class="kw">use</span> <span class="ident">std::os::raw::c_char</span>;
<span class="kw">extern</span> <span class="string">&quot;C&quot;</span> {
<span class="kw">fn</span> <span class="ident">my_printer</span>(<span class="ident">s</span>: <span class="kw-2">*const</span> <span class="ident">c_char</span>);
}
<span class="comment">// We are certain that our string doesn&#39;t have 0 bytes in the middle,</span>
<span class="comment">// so we can .expect()</span>
<span class="kw">let</span> <span class="ident">c_to_print</span> <span class="op">=</span> <span class="ident">CString::new</span>(<span class="string">&quot;Hello, world!&quot;</span>).<span class="ident">expect</span>(<span class="string">&quot;CString::new failed&quot;</span>);
<span class="kw">unsafe</span> {
<span class="ident">my_printer</span>(<span class="ident">c_to_print</span>.<span class="ident">as_ptr</span>());
}</code></pre></div>
<h2 id="safety"><a href="#safety">Safety</a></h2>
<p><code>CString</code> is intended for working with traditional C-style strings
(a sequence of non-nul bytes terminated by a single nul byte); the
primary use case for these kinds of strings is interoperating with C-like
code. Often you will need to transfer ownership to/from that external
code. It is strongly recommended that you thoroughly read through the
documentation of <code>CString</code> before use, as improper ownership management
of <code>CString</code> instances can lead to invalid memory accesses, memory leaks,
and other memory errors.</p>
</div></details><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><div id="implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-CString" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#232">source</a></span><a href="#impl-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.new" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#261">source</a></span><h4 class="code-header">pub fn <a href="#method.new" class="fnname">new</a>&lt;T&gt;(t: T) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.64.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a>, <a class="struct" href="struct.NulError.html" title="struct rustix::ffi::NulError">NulError</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>, <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/alloc/struct.Global.html" title="struct alloc::alloc::Global">Global</a>&gt;&gt;,&nbsp;</span></h4></section></summary><div class="docblock"><p>Creates a new C-compatible string from a container of bytes.</p>
<p>This function will consume the provided data and use the
underlying bytes to construct a new string, ensuring that
there is a trailing 0 byte. This trailing 0 byte will be
appended by this function; the provided data should <em>not</em>
contain any 0 bytes in it.</p>
<h5 id="examples-1"><a href="#examples-1">Examples</a></h5>
<div class='information'><div class='tooltip ignore'></div></div><div class="example-wrap"><pre class="rust rust-example-rendered ignore"><code><span class="kw">use</span> <span class="ident">std::ffi::CString</span>;
<span class="kw">use</span> <span class="ident">std::os::raw::c_char</span>;
<span class="kw">extern</span> <span class="string">&quot;C&quot;</span> { <span class="kw">fn</span> <span class="ident">puts</span>(<span class="ident">s</span>: <span class="kw-2">*const</span> <span class="ident">c_char</span>); }
<span class="kw">let</span> <span class="ident">to_print</span> <span class="op">=</span> <span class="ident">CString::new</span>(<span class="string">&quot;Hello!&quot;</span>).<span class="ident">expect</span>(<span class="string">&quot;CString::new failed&quot;</span>);
<span class="kw">unsafe</span> {
<span class="ident">puts</span>(<span class="ident">to_print</span>.<span class="ident">as_ptr</span>());
}</code></pre></div>
<h5 id="errors"><a href="#errors">Errors</a></h5>
<p>This function will return an error if the supplied bytes contain an
internal 0 byte. The <a href="struct.NulError.html" title="NulError"><code>NulError</code></a> returned will contain the bytes as well as
the position of the nul byte.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_vec_unchecked" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#340">source</a></span><h4 class="code-header">pub unsafe fn <a href="#method.from_vec_unchecked" class="fnname">from_vec_unchecked</a>(v: <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>, <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/alloc/struct.Global.html" title="struct alloc::alloc::Global">Global</a>&gt;) -&gt; <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h4></section></summary><div class="docblock"><p>Creates a C-compatible string by consuming a byte vector,
without checking for interior 0 bytes.</p>
<p>Trailing 0 byte will be appended by this function.</p>
<p>This method is equivalent to <a href="struct.CString.html#method.new" title="CString::new"><code>CString::new</code></a> except that no runtime
assertion is made that <code>v</code> contains no 0 bytes, and it requires an
actual byte vector, not anything that can be converted to one with Into.</p>
<h5 id="examples-2"><a href="#examples-2">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::ffi::CString</span>;
<span class="kw">let</span> <span class="ident">raw</span> <span class="op">=</span> <span class="string">b&quot;foo&quot;</span>.<span class="ident">to_vec</span>();
<span class="kw">unsafe</span> {
<span class="kw">let</span> <span class="ident">c_string</span> <span class="op">=</span> <span class="ident">CString::from_vec_unchecked</span>(<span class="ident">raw</span>);
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_raw" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.4.0">1.4.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#397">source</a></span><h4 class="code-header">pub unsafe fn <a href="#method.from_raw" class="fnname">from_raw</a>(ptr: <a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.pointer.html">*mut </a><a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.i8.html">i8</a>) -&gt; <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h4></section></summary><div class="docblock"><p>Retakes ownership of a <code>CString</code> that was transferred to C via
<a href="struct.CString.html#method.into_raw" title="CString::into_raw"><code>CString::into_raw</code></a>.</p>
<p>Additionally, the length of the string will be recalculated from the pointer.</p>
<h5 id="safety-1"><a href="#safety-1">Safety</a></h5>
<p>This should only ever be called with a pointer that was earlier
obtained by calling <a href="struct.CString.html#method.into_raw" title="CString::into_raw"><code>CString::into_raw</code></a>. Other usage (e.g., trying to take
ownership of a string that was allocated by foreign code) is likely to lead
to undefined behavior or allocator corruption.</p>
<p>It should be noted that the length isnt just “recomputed,” but that
the recomputed length must match the original length from the
<a href="struct.CString.html#method.into_raw" title="CString::into_raw"><code>CString::into_raw</code></a> call. This means the <a href="struct.CString.html#method.into_raw" title="CString::into_raw"><code>CString::into_raw</code></a>/<code>from_raw</code>
methods should not be used when passing the string to C functions that can
modify the strings length.</p>
<blockquote>
<p><strong>Note:</strong> If you need to borrow a string that was allocated by
foreign code, use <a href="struct.CStr.html" title="CStr"><code>CStr</code></a>. If you need to take ownership of
a string that was allocated by foreign code, you will need to
make your own provisions for freeing it appropriately, likely
with the foreign codes API to do that.</p>
</blockquote>
<h5 id="examples-3"><a href="#examples-3">Examples</a></h5>
<p>Creates a <code>CString</code>, pass ownership to an <code>extern</code> function (via raw pointer), then retake
ownership with <code>from_raw</code>:</p>
<div class='information'><div class='tooltip ignore'></div></div><div class="example-wrap"><pre class="rust rust-example-rendered ignore"><code><span class="kw">use</span> <span class="ident">std::ffi::CString</span>;
<span class="kw">use</span> <span class="ident">std::os::raw::c_char</span>;
<span class="kw">extern</span> <span class="string">&quot;C&quot;</span> {
<span class="kw">fn</span> <span class="ident">some_extern_function</span>(<span class="ident">s</span>: <span class="kw-2">*mut</span> <span class="ident">c_char</span>);
}
<span class="kw">let</span> <span class="ident">c_string</span> <span class="op">=</span> <span class="ident">CString::new</span>(<span class="string">&quot;Hello!&quot;</span>).<span class="ident">expect</span>(<span class="string">&quot;CString::new failed&quot;</span>);
<span class="kw">let</span> <span class="ident">raw</span> <span class="op">=</span> <span class="ident">c_string</span>.<span class="ident">into_raw</span>();
<span class="kw">unsafe</span> {
<span class="ident">some_extern_function</span>(<span class="ident">raw</span>);
<span class="kw">let</span> <span class="ident">c_string</span> <span class="op">=</span> <span class="ident">CString::from_raw</span>(<span class="ident">raw</span>);
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into_raw" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.4.0">1.4.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#450">source</a></span><h4 class="code-header">pub fn <a href="#method.into_raw" class="fnname">into_raw</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.pointer.html">*mut </a><a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.i8.html">i8</a></h4></section></summary><div class="docblock"><p>Consumes the <code>CString</code> and transfers ownership of the string to a C caller.</p>
<p>The pointer which this function returns must be returned to Rust and reconstituted using
<a href="struct.CString.html#method.from_raw" title="CString::from_raw"><code>CString::from_raw</code></a> to be properly deallocated. Specifically, one
should <em>not</em> use the standard C <code>free()</code> function to deallocate
this string.</p>
<p>Failure to call <a href="struct.CString.html#method.from_raw" title="CString::from_raw"><code>CString::from_raw</code></a> will lead to a memory leak.</p>
<p>The C side must <strong>not</strong> modify the length of the string (by writing a
<code>null</code> somewhere inside the string or removing the final one) before
it makes it back into Rust using <a href="struct.CString.html#method.from_raw" title="CString::from_raw"><code>CString::from_raw</code></a>. See the safety section
in <a href="struct.CString.html#method.from_raw" title="CString::from_raw"><code>CString::from_raw</code></a>.</p>
<h5 id="examples-4"><a href="#examples-4">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::ffi::CString</span>;
<span class="kw">let</span> <span class="ident">c_string</span> <span class="op">=</span> <span class="ident">CString::new</span>(<span class="string">&quot;foo&quot;</span>).<span class="ident">expect</span>(<span class="string">&quot;CString::new failed&quot;</span>);
<span class="kw">let</span> <span class="ident">ptr</span> <span class="op">=</span> <span class="ident">c_string</span>.<span class="ident">into_raw</span>();
<span class="kw">unsafe</span> {
<span class="macro">assert_eq!</span>(<span class="string">b&#39;f&#39;</span>, <span class="kw-2">*</span><span class="ident">ptr</span> <span class="kw">as</span> <span class="ident">u8</span>);
<span class="macro">assert_eq!</span>(<span class="string">b&#39;o&#39;</span>, <span class="kw-2">*</span><span class="ident">ptr</span>.<span class="ident">offset</span>(<span class="number">1</span>) <span class="kw">as</span> <span class="ident">u8</span>);
<span class="macro">assert_eq!</span>(<span class="string">b&#39;o&#39;</span>, <span class="kw-2">*</span><span class="ident">ptr</span>.<span class="ident">offset</span>(<span class="number">2</span>) <span class="kw">as</span> <span class="ident">u8</span>);
<span class="macro">assert_eq!</span>(<span class="string">b&#39;\0&#39;</span>, <span class="kw-2">*</span><span class="ident">ptr</span>.<span class="ident">offset</span>(<span class="number">3</span>) <span class="kw">as</span> <span class="ident">u8</span>);
<span class="comment">// retake pointer to free memory</span>
<span class="kw">let</span> <span class="kw">_</span> <span class="op">=</span> <span class="ident">CString::from_raw</span>(<span class="ident">ptr</span>);
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into_string" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.7.0">1.7.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#473">source</a></span><h4 class="code-header">pub fn <a href="#method.into_string" class="fnname">into_string</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.64.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>, <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/ffi/c_str/struct.IntoStringError.html" title="struct alloc::ffi::c_str::IntoStringError">IntoStringError</a>&gt;</h4></section></summary><div class="docblock"><p>Converts the <code>CString</code> into a <a href="https://doc.rust-lang.org/1.64.0/alloc/string/struct.String.html" title="String"><code>String</code></a> if it contains valid UTF-8 data.</p>
<p>On failure, ownership of the original <code>CString</code> is returned.</p>
<h5 id="examples-5"><a href="#examples-5">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::ffi::CString</span>;
<span class="kw">let</span> <span class="ident">valid_utf8</span> <span class="op">=</span> <span class="macro">vec!</span>[<span class="string">b&#39;f&#39;</span>, <span class="string">b&#39;o&#39;</span>, <span class="string">b&#39;o&#39;</span>];
<span class="kw">let</span> <span class="ident">cstring</span> <span class="op">=</span> <span class="ident">CString::new</span>(<span class="ident">valid_utf8</span>).<span class="ident">expect</span>(<span class="string">&quot;CString::new failed&quot;</span>);
<span class="macro">assert_eq!</span>(<span class="ident">cstring</span>.<span class="ident">into_string</span>().<span class="ident">expect</span>(<span class="string">&quot;into_string() call failed&quot;</span>), <span class="string">&quot;foo&quot;</span>);
<span class="kw">let</span> <span class="ident">invalid_utf8</span> <span class="op">=</span> <span class="macro">vec!</span>[<span class="string">b&#39;f&#39;</span>, <span class="number">0xff</span>, <span class="string">b&#39;o&#39;</span>, <span class="string">b&#39;o&#39;</span>];
<span class="kw">let</span> <span class="ident">cstring</span> <span class="op">=</span> <span class="ident">CString::new</span>(<span class="ident">invalid_utf8</span>).<span class="ident">expect</span>(<span class="string">&quot;CString::new failed&quot;</span>);
<span class="kw">let</span> <span class="ident">err</span> <span class="op">=</span> <span class="ident">cstring</span>.<span class="ident">into_string</span>().<span class="ident">err</span>().<span class="ident">expect</span>(<span class="string">&quot;into_string().err() failed&quot;</span>);
<span class="macro">assert_eq!</span>(<span class="ident">err</span>.<span class="ident">utf8_error</span>().<span class="ident">valid_up_to</span>(), <span class="number">1</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into_bytes" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.7.0">1.7.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#497">source</a></span><h4 class="code-header">pub fn <a href="#method.into_bytes" class="fnname">into_bytes</a>(self) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>, <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/alloc/struct.Global.html" title="struct alloc::alloc::Global">Global</a>&gt;</h4></section></summary><div class="docblock"><p>Consumes the <code>CString</code> and returns the underlying byte buffer.</p>
<p>The returned buffer does <strong>not</strong> contain the trailing nul
terminator, and it is guaranteed to not have any interior nul
bytes.</p>
<h5 id="examples-6"><a href="#examples-6">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::ffi::CString</span>;
<span class="kw">let</span> <span class="ident">c_string</span> <span class="op">=</span> <span class="ident">CString::new</span>(<span class="string">&quot;foo&quot;</span>).<span class="ident">expect</span>(<span class="string">&quot;CString::new failed&quot;</span>);
<span class="kw">let</span> <span class="ident">bytes</span> <span class="op">=</span> <span class="ident">c_string</span>.<span class="ident">into_bytes</span>();
<span class="macro">assert_eq!</span>(<span class="ident">bytes</span>, <span class="macro">vec!</span>[<span class="string">b&#39;f&#39;</span>, <span class="string">b&#39;o&#39;</span>, <span class="string">b&#39;o&#39;</span>]);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into_bytes_with_nul" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.7.0">1.7.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#518">source</a></span><h4 class="code-header">pub fn <a href="#method.into_bytes_with_nul" class="fnname">into_bytes_with_nul</a>(self) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>, <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/alloc/struct.Global.html" title="struct alloc::alloc::Global">Global</a>&gt;</h4></section></summary><div class="docblock"><p>Equivalent to <a href="struct.CString.html#method.into_bytes" title="CString::into_bytes()"><code>CString::into_bytes()</code></a> except that the
returned vector includes the trailing nul terminator.</p>
<h5 id="examples-7"><a href="#examples-7">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::ffi::CString</span>;
<span class="kw">let</span> <span class="ident">c_string</span> <span class="op">=</span> <span class="ident">CString::new</span>(<span class="string">&quot;foo&quot;</span>).<span class="ident">expect</span>(<span class="string">&quot;CString::new failed&quot;</span>);
<span class="kw">let</span> <span class="ident">bytes</span> <span class="op">=</span> <span class="ident">c_string</span>.<span class="ident">into_bytes_with_nul</span>();
<span class="macro">assert_eq!</span>(<span class="ident">bytes</span>, <span class="macro">vec!</span>[<span class="string">b&#39;f&#39;</span>, <span class="string">b&#39;o&#39;</span>, <span class="string">b&#39;o&#39;</span>, <span class="string">b&#39;\0&#39;</span>]);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_bytes" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#541">source</a></span><h4 class="code-header">pub fn <a href="#method.as_bytes" class="fnname">as_bytes</a>(&amp;self) -&gt; &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>]<span class="notable-traits"><span class="notable-traits-tooltip"><span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>]</span><code class="content"><span class="where fmt-newline">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/std/io/trait.Read.html" title="trait std::io::Read">Read</a> for &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>]</span><span class="where fmt-newline">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/std/io/trait.Write.html" title="trait std::io::Write">Write</a> for &amp;mut [<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>]</span></code></span></span></span></span></h4></section></summary><div class="docblock"><p>Returns the contents of this <code>CString</code> as a slice of bytes.</p>
<p>The returned slice does <strong>not</strong> contain the trailing nul
terminator, and it is guaranteed to not have any interior nul
bytes. If you need the nul terminator, use
<a href="struct.CString.html#method.as_bytes_with_nul" title="CString::as_bytes_with_nul"><code>CString::as_bytes_with_nul</code></a> instead.</p>
<h5 id="examples-8"><a href="#examples-8">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::ffi::CString</span>;
<span class="kw">let</span> <span class="ident">c_string</span> <span class="op">=</span> <span class="ident">CString::new</span>(<span class="string">&quot;foo&quot;</span>).<span class="ident">expect</span>(<span class="string">&quot;CString::new failed&quot;</span>);
<span class="kw">let</span> <span class="ident">bytes</span> <span class="op">=</span> <span class="ident">c_string</span>.<span class="ident">as_bytes</span>();
<span class="macro">assert_eq!</span>(<span class="ident">bytes</span>, <span class="kw-2">&amp;</span>[<span class="string">b&#39;f&#39;</span>, <span class="string">b&#39;o&#39;</span>, <span class="string">b&#39;o&#39;</span>]);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_bytes_with_nul" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#561">source</a></span><h4 class="code-header">pub fn <a href="#method.as_bytes_with_nul" class="fnname">as_bytes_with_nul</a>(&amp;self) -&gt; &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>]<span class="notable-traits"><span class="notable-traits-tooltip"><span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>]</span><code class="content"><span class="where fmt-newline">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/std/io/trait.Read.html" title="trait std::io::Read">Read</a> for &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>]</span><span class="where fmt-newline">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/std/io/trait.Write.html" title="trait std::io::Write">Write</a> for &amp;mut [<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>]</span></code></span></span></span></span></h4></section></summary><div class="docblock"><p>Equivalent to <a href="struct.CString.html#method.as_bytes" title="CString::as_bytes()"><code>CString::as_bytes()</code></a> except that the
returned slice includes the trailing nul terminator.</p>
<h5 id="examples-9"><a href="#examples-9">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::ffi::CString</span>;
<span class="kw">let</span> <span class="ident">c_string</span> <span class="op">=</span> <span class="ident">CString::new</span>(<span class="string">&quot;foo&quot;</span>).<span class="ident">expect</span>(<span class="string">&quot;CString::new failed&quot;</span>);
<span class="kw">let</span> <span class="ident">bytes</span> <span class="op">=</span> <span class="ident">c_string</span>.<span class="ident">as_bytes_with_nul</span>();
<span class="macro">assert_eq!</span>(<span class="ident">bytes</span>, <span class="kw-2">&amp;</span>[<span class="string">b&#39;f&#39;</span>, <span class="string">b&#39;o&#39;</span>, <span class="string">b&#39;o&#39;</span>, <span class="string">b&#39;\0&#39;</span>]);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_c_str" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.20.0">1.20.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#580">source</a></span><h4 class="code-header">pub fn <a href="#method.as_c_str" class="fnname">as_c_str</a>(&amp;self) -&gt; &amp;<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h4></section></summary><div class="docblock"><p>Extracts a <a href="struct.CStr.html" title="CStr"><code>CStr</code></a> slice containing the entire string.</p>
<h5 id="examples-10"><a href="#examples-10">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::ffi</span>::{<span class="ident">CString</span>, <span class="ident">CStr</span>};
<span class="kw">let</span> <span class="ident">c_string</span> <span class="op">=</span> <span class="ident">CString::new</span>(<span class="string">b&quot;foo&quot;</span>.<span class="ident">to_vec</span>()).<span class="ident">expect</span>(<span class="string">&quot;CString::new failed&quot;</span>);
<span class="kw">let</span> <span class="ident">cstr</span> <span class="op">=</span> <span class="ident">c_string</span>.<span class="ident">as_c_str</span>();
<span class="macro">assert_eq!</span>(<span class="ident">cstr</span>,
<span class="ident">CStr::from_bytes_with_nul</span>(<span class="string">b&quot;foo\0&quot;</span>).<span class="ident">expect</span>(<span class="string">&quot;CStr::from_bytes_with_nul failed&quot;</span>));</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into_boxed_c_str" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.20.0">1.20.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#598">source</a></span><h4 class="code-header">pub fn <a href="#method.into_boxed_c_str" class="fnname">into_boxed_c_str</a>(self) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>, <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/alloc/struct.Global.html" title="struct alloc::alloc::Global">Global</a>&gt;</h4></section></summary><div class="docblock"><p>Converts this <code>CString</code> into a boxed <a href="struct.CStr.html" title="CStr"><code>CStr</code></a>.</p>
<h5 id="examples-11"><a href="#examples-11">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::ffi</span>::{<span class="ident">CString</span>, <span class="ident">CStr</span>};
<span class="kw">let</span> <span class="ident">c_string</span> <span class="op">=</span> <span class="ident">CString::new</span>(<span class="string">b&quot;foo&quot;</span>.<span class="ident">to_vec</span>()).<span class="ident">expect</span>(<span class="string">&quot;CString::new failed&quot;</span>);
<span class="kw">let</span> <span class="ident">boxed</span> <span class="op">=</span> <span class="ident">c_string</span>.<span class="ident">into_boxed_c_str</span>();
<span class="macro">assert_eq!</span>(<span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">boxed</span>,
<span class="ident">CStr::from_bytes_with_nul</span>(<span class="string">b&quot;foo\0&quot;</span>).<span class="ident">expect</span>(<span class="string">&quot;CStr::from_bytes_with_nul failed&quot;</span>));</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_vec_with_nul_unchecked" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.58.0">1.58.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#632">source</a></span><h4 class="code-header">pub unsafe fn <a href="#method.from_vec_with_nul_unchecked" class="fnname">from_vec_with_nul_unchecked</a>(v: <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>, <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/alloc/struct.Global.html" title="struct alloc::alloc::Global">Global</a>&gt;) -&gt; <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h4></section></summary><div class="docblock"><p>Converts a <code><a href="https://doc.rust-lang.org/1.64.0/alloc/vec/struct.Vec.html" title="Vec">Vec</a>&lt;<a href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html" title="u8">u8</a>&gt;</code> to a <a href="struct.CString.html" title="CString"><code>CString</code></a> without checking the
invariants on the given <a href="https://doc.rust-lang.org/1.64.0/alloc/vec/struct.Vec.html" title="Vec"><code>Vec</code></a>.</p>
<h5 id="safety-2"><a href="#safety-2">Safety</a></h5>
<p>The given <a href="https://doc.rust-lang.org/1.64.0/alloc/vec/struct.Vec.html" title="Vec"><code>Vec</code></a> <strong>must</strong> have one nul byte as its last element.
This means it cannot be empty nor have any other nul byte anywhere else.</p>
<h5 id="example"><a href="#example">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::ffi::CString</span>;
<span class="macro">assert_eq!</span>(
<span class="kw">unsafe</span> { <span class="ident">CString::from_vec_with_nul_unchecked</span>(<span class="string">b&quot;abc\0&quot;</span>.<span class="ident">to_vec</span>()) },
<span class="kw">unsafe</span> { <span class="ident">CString::from_vec_unchecked</span>(<span class="string">b&quot;abc&quot;</span>.<span class="ident">to_vec</span>()) }
);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_vec_with_nul" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.58.0">1.58.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#675">source</a></span><h4 class="code-header">pub fn <a href="#method.from_vec_with_nul" class="fnname">from_vec_with_nul</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;v: <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>, <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/alloc/struct.Global.html" title="struct alloc::alloc::Global">Global</a>&gt;<br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.64.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a>, <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/ffi/c_str/struct.FromVecWithNulError.html" title="struct alloc::ffi::c_str::FromVecWithNulError">FromVecWithNulError</a>&gt;</h4></section></summary><div class="docblock"><p>Attempts to converts a <code><a href="https://doc.rust-lang.org/1.64.0/alloc/vec/struct.Vec.html" title="Vec">Vec</a>&lt;<a href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html" title="u8">u8</a>&gt;</code> to a <a href="struct.CString.html" title="CString"><code>CString</code></a>.</p>
<p>Runtime checks are present to ensure there is only one nul byte in the
<a href="https://doc.rust-lang.org/1.64.0/alloc/vec/struct.Vec.html" title="Vec"><code>Vec</code></a>, its last element.</p>
<h5 id="errors-1"><a href="#errors-1">Errors</a></h5>
<p>If a nul byte is present and not the last element or no nul bytes
is present, an error will be returned.</p>
<h5 id="examples-12"><a href="#examples-12">Examples</a></h5>
<p>A successful conversion will produce the same result as <a href="struct.CString.html#method.new" title="CString::new"><code>CString::new</code></a>
when called without the ending nul byte.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::ffi::CString</span>;
<span class="macro">assert_eq!</span>(
<span class="ident">CString::from_vec_with_nul</span>(<span class="string">b&quot;abc\0&quot;</span>.<span class="ident">to_vec</span>())
.<span class="ident">expect</span>(<span class="string">&quot;CString::from_vec_with_nul failed&quot;</span>),
<span class="ident">CString::new</span>(<span class="string">b&quot;abc&quot;</span>.<span class="ident">to_vec</span>()).<span class="ident">expect</span>(<span class="string">&quot;CString::new failed&quot;</span>)
);</code></pre></div>
<p>An incorrectly formatted <a href="https://doc.rust-lang.org/1.64.0/alloc/vec/struct.Vec.html" title="Vec"><code>Vec</code></a> will produce an error.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::ffi</span>::{<span class="ident">CString</span>, <span class="ident">FromVecWithNulError</span>};
<span class="comment">// Interior nul byte</span>
<span class="kw">let</span> <span class="kw">_</span>: <span class="ident">FromVecWithNulError</span> <span class="op">=</span> <span class="ident">CString::from_vec_with_nul</span>(<span class="string">b&quot;a\0bc&quot;</span>.<span class="ident">to_vec</span>()).<span class="ident">unwrap_err</span>();
<span class="comment">// No nul byte</span>
<span class="kw">let</span> <span class="kw">_</span>: <span class="ident">FromVecWithNulError</span> <span class="op">=</span> <span class="ident">CString::from_vec_with_nul</span>(<span class="string">b&quot;abc&quot;</span>.<span class="ident">to_vec</span>()).<span class="ident">unwrap_err</span>();</code></pre></div>
</div></details></div></details></div><h2 id="deref-methods-CStr" class="small-section-header"><span>Methods from <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a>&lt;Target = <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>&gt;</span><a href="#deref-methods-CStr" class="anchor"></a></h2><div id="deref-methods-CStr-1"><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_ptr" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/ffi/c_str.rs.html#475">source</a></span><h4 class="code-header">pub fn <a href="#method.as_ptr" class="fnname">as_ptr</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.pointer.html">*const </a><a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.i8.html">i8</a></h4></section></summary><div class="docblock"><p>Returns the inner pointer to this C string.</p>
<p>The returned pointer will be valid for as long as <code>self</code> is, and points
to a contiguous region of memory terminated with a 0 byte to represent
the end of the string.</p>
<p><strong>WARNING</strong></p>
<p>The returned pointer is read-only; writing to it (including passing it
to C code that writes to it) causes undefined behavior.</p>
<p>It is your responsibility to make sure that the underlying memory is not
freed too early. For example, the following code will cause undefined
behavior when <code>ptr</code> is used inside the <code>unsafe</code> block:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::ffi::CString</span>;
<span class="kw">let</span> <span class="ident">ptr</span> <span class="op">=</span> <span class="ident">CString::new</span>(<span class="string">&quot;Hello&quot;</span>).<span class="ident">expect</span>(<span class="string">&quot;CString::new failed&quot;</span>).<span class="ident">as_ptr</span>();
<span class="kw">unsafe</span> {
<span class="comment">// `ptr` is dangling</span>
<span class="kw-2">*</span><span class="ident">ptr</span>;
}</code></pre></div>
<p>This happens because the pointer returned by <code>as_ptr</code> does not carry any
lifetime information and the <code>CString</code> is deallocated immediately after
the <code>CString::new(&quot;Hello&quot;).expect(&quot;CString::new failed&quot;).as_ptr()</code>
expression is evaluated.
To fix the problem, bind the <code>CString</code> to a local variable:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::ffi::CString</span>;
<span class="kw">let</span> <span class="ident">hello</span> <span class="op">=</span> <span class="ident">CString::new</span>(<span class="string">&quot;Hello&quot;</span>).<span class="ident">expect</span>(<span class="string">&quot;CString::new failed&quot;</span>);
<span class="kw">let</span> <span class="ident">ptr</span> <span class="op">=</span> <span class="ident">hello</span>.<span class="ident">as_ptr</span>();
<span class="kw">unsafe</span> {
<span class="comment">// `ptr` is valid because `hello` is in scope</span>
<span class="kw-2">*</span><span class="ident">ptr</span>;
}</code></pre></div>
<p>This way, the lifetime of the <code>CString</code> in <code>hello</code> encompasses
the lifetime of <code>ptr</code> and the <code>unsafe</code> block.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.to_bytes" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/ffi/c_str.rs.html#500">source</a></span><h4 class="code-header">pub fn <a href="#method.to_bytes" class="fnname">to_bytes</a>(&amp;self) -&gt; &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>]<span class="notable-traits"><span class="notable-traits-tooltip"><span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>]</span><code class="content"><span class="where fmt-newline">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/std/io/trait.Read.html" title="trait std::io::Read">Read</a> for &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>]</span><span class="where fmt-newline">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/std/io/trait.Write.html" title="trait std::io::Write">Write</a> for &amp;mut [<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>]</span></code></span></span></span></span></h4></section></summary><div class="docblock"><p>Converts this C string to a byte slice.</p>
<p>The returned slice will <strong>not</strong> contain the trailing nul terminator that this C
string has.</p>
<blockquote>
<p><strong>Note</strong>: This method is currently implemented as a constant-time
cast, but it is planned to alter its definition in the future to
perform the length calculation whenever this method is called.</p>
</blockquote>
<h5 id="examples-13"><a href="#examples-13">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::ffi::CStr</span>;
<span class="kw">let</span> <span class="ident">cstr</span> <span class="op">=</span> <span class="ident">CStr::from_bytes_with_nul</span>(<span class="string">b&quot;foo\0&quot;</span>).<span class="ident">expect</span>(<span class="string">&quot;CStr::from_bytes_with_nul failed&quot;</span>);
<span class="macro">assert_eq!</span>(<span class="ident">cstr</span>.<span class="ident">to_bytes</span>(), <span class="string">b&quot;foo&quot;</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.to_bytes_with_nul" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/ffi/c_str.rs.html#527">source</a></span><h4 class="code-header">pub fn <a href="#method.to_bytes_with_nul" class="fnname">to_bytes_with_nul</a>(&amp;self) -&gt; &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>]<span class="notable-traits"><span class="notable-traits-tooltip"><span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>]</span><code class="content"><span class="where fmt-newline">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/std/io/trait.Read.html" title="trait std::io::Read">Read</a> for &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>]</span><span class="where fmt-newline">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/std/io/trait.Write.html" title="trait std::io::Write">Write</a> for &amp;mut [<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>]</span></code></span></span></span></span></h4></section></summary><div class="docblock"><p>Converts this C string to a byte slice containing the trailing 0 byte.</p>
<p>This function is the equivalent of <a href="struct.CStr.html#method.to_bytes" title="CStr::to_bytes"><code>CStr::to_bytes</code></a> except that it
will retain the trailing nul terminator instead of chopping it off.</p>
<blockquote>
<p><strong>Note</strong>: This method is currently implemented as a 0-cost cast, but
it is planned to alter its definition in the future to perform the
length calculation whenever this method is called.</p>
</blockquote>
<h5 id="examples-14"><a href="#examples-14">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::ffi::CStr</span>;
<span class="kw">let</span> <span class="ident">cstr</span> <span class="op">=</span> <span class="ident">CStr::from_bytes_with_nul</span>(<span class="string">b&quot;foo\0&quot;</span>).<span class="ident">expect</span>(<span class="string">&quot;CStr::from_bytes_with_nul failed&quot;</span>);
<span class="macro">assert_eq!</span>(<span class="ident">cstr</span>.<span class="ident">to_bytes_with_nul</span>(), <span class="string">b&quot;foo\0&quot;</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.to_str" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.4.0">1.4.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/ffi/c_str.rs.html#550">source</a></span><h4 class="code-header">pub fn <a href="#method.to_str" class="fnname">to_str</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.64.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;&amp;<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.str.html">str</a>, <a class="struct" href="https://doc.rust-lang.org/1.64.0/core/str/error/struct.Utf8Error.html" title="struct core::str::error::Utf8Error">Utf8Error</a>&gt;</h4></section></summary><div class="docblock"><p>Yields a <code>&amp;<a href="https://doc.rust-lang.org/1.64.0/std/primitive.str.html" title="str">str</a></code> slice if the <code>CStr</code> contains valid UTF-8.</p>
<p>If the contents of the <code>CStr</code> are valid UTF-8 data, this
function will return the corresponding <code>&amp;<a href="https://doc.rust-lang.org/1.64.0/std/primitive.str.html" title="str">str</a></code> slice. Otherwise,
it will return an error with details of where UTF-8 validation failed.</p>
<h5 id="examples-15"><a href="#examples-15">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::ffi::CStr</span>;
<span class="kw">let</span> <span class="ident">cstr</span> <span class="op">=</span> <span class="ident">CStr::from_bytes_with_nul</span>(<span class="string">b&quot;foo\0&quot;</span>).<span class="ident">expect</span>(<span class="string">&quot;CStr::from_bytes_with_nul failed&quot;</span>);
<span class="macro">assert_eq!</span>(<span class="ident">cstr</span>.<span class="ident">to_str</span>(), <span class="prelude-val">Ok</span>(<span class="string">&quot;foo&quot;</span>));</code></pre></div>
</div></details></div></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-AsRef%3CCStr%3E-for-CString" class="impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.7.0">1.7.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#1049">source</a></span><a href="#impl-AsRef%3CCStr%3E-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>&gt; for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_ref" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#1051">source</a></span><a href="#method.as_ref" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/convert/trait.AsRef.html#tymethod.as_ref" class="fnname">as_ref</a>(&amp;self) -&gt; &amp;<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h4></section></summary><div class='docblock'><p>Converts this type into a shared reference of the (usually inferred) input type.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Borrow%3CCStr%3E-for-CString" class="impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.3.0">1.3.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#746">source</a></span><a href="#impl-Borrow%3CCStr%3E-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a>&lt;<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>&gt; for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#748">source</a></span><a href="#method.borrow" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/borrow/trait.Borrow.html#tymethod.borrow" class="fnname">borrow</a>(&amp;self) -&gt; &amp;<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h4></section></summary><div class='docblock'><p>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.64.0/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Clone-for-CString" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#109">source</a></span><a href="#impl-Clone-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.clone" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#109">source</a></span><a href="#method.clone" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/clone/trait.Clone.html#tymethod.clone" class="fnname">clone</a>(&amp;self) -&gt; <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h4></section></summary><div class='docblock'><p>Returns a copy of the value. <a href="https://doc.rust-lang.org/1.64.0/core/clone/trait.Clone.html#tymethod.clone">Read more</a></p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.clone_from" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/clone.rs.html#132-134">source</a></span><a href="#method.clone_from" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/clone/trait.Clone.html#method.clone_from" class="fnname">clone_from</a>(&amp;mut self, source: <a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.reference.html">&amp;</a>Self)</h4></section></summary><div class='docblock'><p>Performs copy-assignment from <code>source</code>. <a href="https://doc.rust-lang.org/1.64.0/core/clone/trait.Clone.html#method.clone_from">Read more</a></p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Debug-for-CString" class="impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#719">source</a></span><a href="#impl-Debug-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#720">source</a></span><a href="#method.fmt" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/fmt/trait.Debug.html#tymethod.fmt" class="fnname">fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="https://doc.rust-lang.org/1.64.0/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>&lt;'_&gt;) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.64.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.unit.html">()</a>, <a class="struct" href="https://doc.rust-lang.org/1.64.0/core/fmt/struct.Error.html" title="struct core::fmt::Error">Error</a>&gt;</h4></section></summary><div class='docblock'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/1.64.0/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Default-for-CString" class="impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.10.0">1.10.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#737">source</a></span><a href="#impl-Default-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/default/trait.Default.html" title="trait core::default::Default">Default</a> for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.default" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#739">source</a></span><a href="#method.default" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/default/trait.Default.html#tymethod.default" class="fnname">default</a>() -&gt; <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h4></section></summary><div class="docblock"><p>Creates an empty <code>CString</code>.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Deref-for-CString" class="impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#709">source</a></span><a href="#impl-Deref-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a> for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Target" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Target" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.64.0/core/ops/deref/trait.Deref.html#associatedtype.Target" class="associatedtype">Target</a> = <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h4></section></summary><div class='docblock'><p>The resulting type after dereferencing.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.deref" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#713">source</a></span><a href="#method.deref" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/ops/deref/trait.Deref.html#tymethod.deref" class="fnname">deref</a>(&amp;self) -&gt; &amp;<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h4></section></summary><div class='docblock'><p>Dereferences the value.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Drop-for-CString" class="impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.13.0">1.13.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#699">source</a></span><a href="#impl-Drop-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/ops/drop/trait.Drop.html" title="trait core::ops::drop::Drop">Drop</a> for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.drop" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#701">source</a></span><a href="#method.drop" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/ops/drop/trait.Drop.html#tymethod.drop" class="fnname">drop</a>(&amp;mut self)</h4></section></summary><div class='docblock'><p>Executes the destructor for this type. <a href="https://doc.rust-lang.org/1.64.0/core/ops/drop/trait.Drop.html#tymethod.drop">Read more</a></p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-From%3C%26CStr%3E-for-CString" class="impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.7.0">1.7.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#1032">source</a></span><a href="#impl-From%3C%26CStr%3E-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;&amp;<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>&gt; for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from-3" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#1033">source</a></span><a href="#method.from-3" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(s: &amp;<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>) -&gt; <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h4></section></summary><div class='docblock'><p>Converts to this type from the input type.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-From%3CBox%3CCStr%2C%20Global%3E%3E-for-CString" class="impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.18.0">1.18.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#788">source</a></span><a href="#impl-From%3CBox%3CCStr%2C%20Global%3E%3E-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;<a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>, <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/alloc/struct.Global.html" title="struct alloc::alloc::Global">Global</a>&gt;&gt; for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from-1" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#791">source</a></span><a href="#method.from-1" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(s: <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>, <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/alloc/struct.Global.html" title="struct alloc::alloc::Global">Global</a>&gt;) -&gt; <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h4></section></summary><div class="docblock"><p>Converts a <code><a href="https://doc.rust-lang.org/1.64.0/alloc/boxed/struct.Box.html" title="Box">Box</a>&lt;<a href="struct.CStr.html" title="CStr">CStr</a>&gt;</code> into a <a href="struct.CString.html" title="CString"><code>CString</code></a> without copying or allocating.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-From%3CCow%3C%27a%2C%20CStr%3E%3E-for-CString" class="impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.28.0">1.28.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#754">source</a></span><a href="#impl-From%3CCow%3C%27a%2C%20CStr%3E%3E-for-CString" class="anchor"></a><h3 class="code-header in-band">impl&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;<a class="enum" href="https://doc.rust-lang.org/1.64.0/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a>&lt;'a, <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>&gt;&gt; for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from-2" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#758">source</a></span><a href="#method.from-2" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(s: <a class="enum" href="https://doc.rust-lang.org/1.64.0/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a>&lt;'a, <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>&gt;) -&gt; <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h4></section></summary><div class="docblock"><p>Converts a <code>Cow&lt;'a, CStr&gt;</code> into a <code>CString</code>, by copying the contents if they are
borrowed.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-From%3CVec%3CNonZeroU8%2C%20Global%3E%3E-for-CString" class="impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.43.0">1.43.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#798">source</a></span><a href="#impl-From%3CVec%3CNonZeroU8%2C%20Global%3E%3E-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;<a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="struct" href="https://doc.rust-lang.org/1.64.0/core/num/nonzero/struct.NonZeroU8.html" title="struct core::num::nonzero::NonZeroU8">NonZeroU8</a>, <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/alloc/struct.Global.html" title="struct alloc::alloc::Global">Global</a>&gt;&gt; for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#802">source</a></span><a href="#method.from" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(v: <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="struct" href="https://doc.rust-lang.org/1.64.0/core/num/nonzero/struct.NonZeroU8.html" title="struct core::num::nonzero::NonZeroU8">NonZeroU8</a>, <a class="struct" href="https://doc.rust-lang.org/1.64.0/alloc/alloc/struct.Global.html" title="struct alloc::alloc::Global">Global</a>&gt;) -&gt; <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h4></section></summary><div class="docblock"><p>Converts a <code><a href="https://doc.rust-lang.org/1.64.0/alloc/vec/struct.Vec.html" title="Vec">Vec</a>&lt;<a href="https://doc.rust-lang.org/1.64.0/core/num/nonzero/struct.NonZeroU8.html" title="NonZeroU8">NonZeroU8</a>&gt;</code> into a <a href="struct.CString.html" title="CString"><code>CString</code></a> without
copying nor checking for inner null bytes.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Hash-for-CString" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#109">source</a></span><a href="#impl-Hash-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.hash" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#109">source</a></span><a href="#method.hash" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/hash/trait.Hash.html#tymethod.hash" class="fnname">hash</a>&lt;__H&gt;(&amp;self, state: <a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.reference.html">&amp;mut </a>__H) <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;__H: <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/hash/trait.Hasher.html" title="trait core::hash::Hasher">Hasher</a>,&nbsp;</span></h4></section></summary><div class='docblock'><p>Feeds this value into the given <a href="https://doc.rust-lang.org/1.64.0/core/hash/trait.Hasher.html" title="Hasher"><code>Hasher</code></a>. <a href="https://doc.rust-lang.org/1.64.0/core/hash/trait.Hash.html#tymethod.hash">Read more</a></p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.hash_slice" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.3.0">1.3.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/hash/mod.rs.html#237-239">source</a></span><a href="#method.hash_slice" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/hash/trait.Hash.html#method.hash_slice" class="fnname">hash_slice</a>&lt;H&gt;(data: &amp;<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.slice.html">[Self]</a>, state: <a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.reference.html">&amp;mut </a>H) <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;H: <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/hash/trait.Hasher.html" title="trait core::hash::Hasher">Hasher</a>,&nbsp;</span></h4></section></summary><div class='docblock'><p>Feeds a slice of this type into the given <a href="https://doc.rust-lang.org/1.64.0/core/hash/trait.Hasher.html" title="Hasher"><code>Hasher</code></a>. <a href="https://doc.rust-lang.org/1.64.0/core/hash/trait.Hash.html#method.hash_slice">Read more</a></p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Index%3CRangeFull%3E-for-CString" class="impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.7.0">1.7.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#1039">source</a></span><a href="#impl-Index%3CRangeFull%3E-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/ops/index/trait.Index.html" title="trait core::ops::index::Index">Index</a>&lt;<a class="struct" href="https://doc.rust-lang.org/1.64.0/core/ops/range/struct.RangeFull.html" title="struct core::ops::range::RangeFull">RangeFull</a>&gt; for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Output" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Output" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.64.0/core/ops/index/trait.Index.html#associatedtype.Output" class="associatedtype">Output</a> = <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h4></section></summary><div class='docblock'><p>The returned type after indexing.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.index" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#1043">source</a></span><a href="#method.index" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/ops/index/trait.Index.html#tymethod.index" class="fnname">index</a>(&amp;self, _index: <a class="struct" href="https://doc.rust-lang.org/1.64.0/core/ops/range/struct.RangeFull.html" title="struct core::ops::range::RangeFull">RangeFull</a>) -&gt; &amp;<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h4></section></summary><div class='docblock'><p>Performs the indexing (<code>container[index]</code>) operation. <a href="https://doc.rust-lang.org/1.64.0/core/ops/index/trait.Index.html#tymethod.index">Read more</a></p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Ord-for-CString" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#109">source</a></span><a href="#impl-Ord-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a> for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.cmp" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#109">source</a></span><a href="#method.cmp" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.Ord.html#tymethod.cmp" class="fnname">cmp</a>(&amp;self, other: &amp;<a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.64.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a></h4></section></summary><div class='docblock'><p>This method returns an <a href="https://doc.rust-lang.org/1.64.0/core/cmp/enum.Ordering.html" title="Ordering"><code>Ordering</code></a> between <code>self</code> and <code>other</code>. <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.Ord.html#tymethod.cmp">Read more</a></p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.max" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.21.0">1.21.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/cmp.rs.html#800-803">source</a></span><a href="#method.max" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.Ord.html#method.max" class="fnname">max</a>(self, other: Self) -&gt; Self</h4></section></summary><div class='docblock'><p>Compares and returns the maximum of two values. <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.Ord.html#method.max">Read more</a></p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.min" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.21.0">1.21.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/cmp.rs.html#827-830">source</a></span><a href="#method.min" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.Ord.html#method.min" class="fnname">min</a>(self, other: Self) -&gt; Self</h4></section></summary><div class='docblock'><p>Compares and returns the minimum of two values. <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.Ord.html#method.min">Read more</a></p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.clamp" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.50.0">1.50.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/cmp.rs.html#859-863">source</a></span><a href="#method.clamp" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.Ord.html#method.clamp" class="fnname">clamp</a>(self, min: Self, max: Self) -&gt; Self <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>&lt;Self&gt;,&nbsp;</span></h4></section></summary><div class='docblock'><p>Restrict a value to a certain interval. <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.Ord.html#method.clamp">Read more</a></p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-PartialEq%3CCString%3E-for-CString" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#109">source</a></span><a href="#impl-PartialEq%3CCString%3E-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a>&lt;<a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a>&gt; for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.eq" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#109">source</a></span><a href="#method.eq" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.PartialEq.html#tymethod.eq" class="fnname">eq</a>(&amp;self, other: &amp;<a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used
by <code>==</code>. <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.ne" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#109">source</a></span><a href="#method.ne" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.PartialEq.html#method.ne" class="fnname">ne</a>(&amp;self, other: &amp;<a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'><p>This method tests for <code>!=</code>.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-PartialOrd%3CCString%3E-for-CString" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#109">source</a></span><a href="#impl-PartialOrd%3CCString%3E-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>&lt;<a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a>&gt; for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.partial_cmp" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#109">source</a></span><a href="#method.partial_cmp" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.PartialOrd.html#tymethod.partial_cmp" class="fnname">partial_cmp</a>(&amp;self, other: &amp;<a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.64.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="https://doc.rust-lang.org/1.64.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>&gt;</h4></section></summary><div class='docblock'><p>This method returns an ordering between <code>self</code> and <code>other</code> values if one exists. <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.PartialOrd.html#tymethod.partial_cmp">Read more</a></p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.lt" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/cmp.rs.html#1122">source</a></span><a href="#method.lt" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.PartialOrd.html#method.lt" class="fnname">lt</a>(&amp;self, other: <a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.reference.html">&amp;</a>Rhs) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'><p>This method tests less than (for <code>self</code> and <code>other</code>) and is used by the <code>&lt;</code> operator. <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.PartialOrd.html#method.lt">Read more</a></p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.le" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/cmp.rs.html#1141">source</a></span><a href="#method.le" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.PartialOrd.html#method.le" class="fnname">le</a>(&amp;self, other: <a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.reference.html">&amp;</a>Rhs) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'><p>This method tests less than or equal to (for <code>self</code> and <code>other</code>) and is used by the <code>&lt;=</code>
operator. <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.PartialOrd.html#method.le">Read more</a></p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.gt" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/cmp.rs.html#1163">source</a></span><a href="#method.gt" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.PartialOrd.html#method.gt" class="fnname">gt</a>(&amp;self, other: <a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.reference.html">&amp;</a>Rhs) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'><p>This method tests greater than (for <code>self</code> and <code>other</code>) and is used by the <code>&gt;</code> operator. <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.PartialOrd.html#method.gt">Read more</a></p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.ge" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/cmp.rs.html#1182">source</a></span><a href="#method.ge" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.PartialOrd.html#method.ge" class="fnname">ge</a>(&amp;self, other: <a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.reference.html">&amp;</a>Rhs) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'><p>This method tests greater than or equal to (for <code>self</code> and <code>other</code>) and is used by the <code>&gt;=</code>
operator. <a href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.PartialOrd.html#method.ge">Read more</a></p>
</div></details></div></details><section id="impl-Eq-for-CString" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#109">source</a></span><a href="#impl-Eq-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section><section id="impl-StructuralEq-for-CString" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#109">source</a></span><a href="#impl-StructuralEq-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/marker/trait.StructuralEq.html" title="trait core::marker::StructuralEq">StructuralEq</a> for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section><section id="impl-StructuralPartialEq-for-CString" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/ffi/c_str.rs.html#109">source</a></span><a href="#impl-StructuralPartialEq-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/marker/trait.StructuralPartialEq.html" title="trait core::marker::StructuralPartialEq">StructuralPartialEq</a> for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><section id="impl-RefUnwindSafe-for-CString" class="impl has-srclink"><a href="#impl-RefUnwindSafe-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section><section id="impl-Send-for-CString" class="impl has-srclink"><a href="#impl-Send-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section><section id="impl-Sync-for-CString" class="impl has-srclink"><a href="#impl-Sync-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section><section id="impl-Unpin-for-CString" class="impl has-srclink"><a href="#impl-Unpin-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section><section id="impl-UnwindSafe-for-CString" class="impl has-srclink"><a href="#impl-UnwindSafe-for-CString" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Any-for-CString" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/any.rs.html#203">source</a></span><a href="#impl-Any-for-CString" class="anchor"></a><h3 class="code-header in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/1.64.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/any.rs.html#204">source</a></span><a href="#method.type_id" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/any/trait.Any.html#tymethod.type_id" class="fnname">type_id</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.64.0/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'><p>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/1.64.0/core/any/trait.Any.html#tymethod.type_id">Read more</a></p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-CString" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/borrow.rs.html#209">source</a></span><a href="#impl-Borrow%3CT%3E-for-CString" class="anchor"></a><h3 class="code-header in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a>&lt;T&gt; for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="https://doc.rust-lang.org/1.64.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow-1" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/borrow.rs.html#211">source</a></span><a href="#method.borrow-1" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/borrow/trait.Borrow.html#tymethod.borrow" class="fnname">borrow</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.reference.html">&amp;</a>T</h4></section></summary><div class='docblock'><p>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.64.0/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-CString" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/borrow.rs.html#218">source</a></span><a href="#impl-BorrowMut%3CT%3E-for-CString" class="anchor"></a><h3 class="code-header in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a>&lt;T&gt; for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="https://doc.rust-lang.org/1.64.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/borrow.rs.html#219">source</a></span><a href="#method.borrow_mut" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fnname">borrow_mut</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.reference.html">&amp;mut </a>T</h4></section></summary><div class='docblock'><p>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.64.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-CString" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/convert/mod.rs.html#557">source</a></span><a href="#impl-From%3CT%3E-for-CString" class="anchor"></a><h3 class="code-header in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;T&gt; for T</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from-4" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/convert/mod.rs.html#559">source</a></span><a href="#method.from-4" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(t: T) -&gt; T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-CString" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/convert/mod.rs.html#541">source</a></span><a href="#impl-Into%3CU%3E-for-CString" class="anchor"></a><h3 class="code-header in-band">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;U&gt; for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;T&gt;,&nbsp;</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/convert/mod.rs.html#549">source</a></span><a href="#method.into" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/convert/trait.Into.html#tymethod.into" class="fnname">into</a>(self) -&gt; U</h4></section></summary><div class="docblock"><p>Calls <code>U::from(self)</code>.</p>
<p>That is, this conversion is whatever the implementation of
<code><a href="https://doc.rust-lang.org/1.64.0/core/convert/trait.From.html" title="From">From</a>&lt;T&gt; for U</code> chooses to do.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-ToOwned-for-CString" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/borrow.rs.html#83">source</a></span><a href="#impl-ToOwned-for-CString" class="anchor"></a><h3 class="code-header in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.64.0/alloc/borrow/trait.ToOwned.html" title="trait alloc::borrow::ToOwned">ToOwned</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,&nbsp;</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Owned" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Owned" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.64.0/alloc/borrow/trait.ToOwned.html#associatedtype.Owned" class="associatedtype">Owned</a> = T</h4></section></summary><div class='docblock'><p>The resulting type after obtaining ownership.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.to_owned" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/borrow.rs.html#88">source</a></span><a href="#method.to_owned" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/alloc/borrow/trait.ToOwned.html#tymethod.to_owned" class="fnname">to_owned</a>(&amp;self) -&gt; T</h4></section></summary><div class='docblock'><p>Creates owned data from borrowed data, usually by cloning. <a href="https://doc.rust-lang.org/1.64.0/alloc/borrow/trait.ToOwned.html#tymethod.to_owned">Read more</a></p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.clone_into" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/alloc/borrow.rs.html#92">source</a></span><a href="#method.clone_into" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/alloc/borrow/trait.ToOwned.html#method.clone_into" class="fnname">clone_into</a>(&amp;self, target: <a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.reference.html">&amp;mut </a>T)</h4></section></summary><div class='docblock'><p>Uses borrowed data to replace owned data, usually by cloning. <a href="https://doc.rust-lang.org/1.64.0/alloc/borrow/trait.ToOwned.html#method.clone_into">Read more</a></p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-CString" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/convert/mod.rs.html#598">source</a></span><a href="#impl-TryFrom%3CU%3E-for-CString" class="anchor"></a><h3 class="code-header in-band">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;U&gt; for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;T&gt;,&nbsp;</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.64.0/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/1.64.0/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></h4></section></summary><div class='docblock'><p>The type returned in the event of a conversion error.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/convert/mod.rs.html#604">source</a></span><a href="#method.try_from" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/convert/trait.TryFrom.html#tymethod.try_from" class="fnname">try_from</a>(value: U) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.64.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;T, &lt;T as <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;U&gt;&gt;::<a class="associatedtype" href="https://doc.rust-lang.org/1.64.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>&gt;</h4></section></summary><div class='docblock'><p>Performs the conversion.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-CString" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/convert/mod.rs.html#583">source</a></span><a href="#impl-TryInto%3CU%3E-for-CString" class="anchor"></a><h3 class="code-header in-band">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a>&lt;U&gt; for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;,&nbsp;</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error-1" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.64.0/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = &lt;U as <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;&gt;::<a class="associatedtype" href="https://doc.rust-lang.org/1.64.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></h4></section></summary><div class='docblock'><p>The type returned in the event of a conversion error.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/convert/mod.rs.html#589">source</a></span><a href="#method.try_into" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.64.0/core/convert/trait.TryInto.html#tymethod.try_into" class="fnname">try_into</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.64.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;U, &lt;U as <a class="trait" href="https://doc.rust-lang.org/1.64.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;&gt;::<a class="associatedtype" href="https://doc.rust-lang.org/1.64.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>&gt;</h4></section></summary><div class='docblock'><p>Performs the conversion.</p>
</div></details></div></details></div></section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="rustix" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.64.0 (a55dd71d5 2022-09-19)" ></div></body></html>