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

259 lines
73 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="Representation of a borrowed C string."><meta name="keywords" content="rust, rustlang, rust-lang, CStr"><title>CStr 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="#">CStr</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_ptr">as_ptr</a></li><li><a href="#method.from_bytes_until_nul">from_bytes_until_nul</a></li><li><a href="#method.from_bytes_with_nul">from_bytes_with_nul</a></li><li><a href="#method.from_bytes_with_nul_unchecked">from_bytes_with_nul_unchecked</a></li><li><a href="#method.from_ptr">from_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-CStr">AsRef&lt;CStr&gt;</a></li><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-Debug-for-CStr">Debug</a></li><li><a href="#impl-Default-for-%26CStr">Default</a></li><li><a href="#impl-Eq-for-CStr">Eq</a></li><li><a href="#impl-From%3C%26CStr%3E-for-CString">From&lt;&amp;CStr&gt;</a></li><li><a href="#impl-Hash-for-CStr">Hash</a></li><li><a href="#impl-Index%3CRangeFrom%3Cusize%3E%3E-for-CStr">Index&lt;RangeFrom&lt;usize&gt;&gt;</a></li><li><a href="#impl-Ord-for-CStr">Ord</a></li><li><a href="#impl-PartialEq%3CCStr%3E-for-CStr">PartialEq&lt;CStr&gt;</a></li><li><a href="#impl-PartialOrd%3CCStr%3E-for-CStr">PartialOrd&lt;CStr&gt;</a></li><li><a href="#impl-ToOwned-for-CStr">ToOwned</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-CStr">RefUnwindSafe</a></li><li><a href="#impl-Send-for-CStr">Send</a></li><li><a href="#impl-Sized-for-CStr">!Sized</a></li><li><a href="#impl-Sync-for-CStr">Sync</a></li><li><a href="#impl-Unpin-for-CStr">Unpin</a></li><li><a href="#impl-UnwindSafe-for-CStr">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-CStr">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-CStr">Borrow&lt;T&gt;</a></li><li><a href="#impl-BorrowMut%3CT%3E-for-CStr">BorrowMut&lt;T&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="#">CStr</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/core/ffi/c_str.rs.html#88">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 CStr { /* private fields */ }</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Representation of a borrowed C string.</p>
<p>This type represents a borrowed reference to a nul-terminated
array of bytes. It can be constructed safely from a <code>&amp;[<a href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html" title="u8">u8</a>]</code>
slice, or unsafely from a raw <code>*const c_char</code>. It can then be
converted to a Rust <code>&amp;<a href="https://doc.rust-lang.org/1.64.0/std/primitive.str.html" title="str">str</a></code> by performing UTF-8 validation, or
into an owned <code>CString</code>.</p>
<p><code>&amp;CStr</code> is to <code>CString</code> as <code>&amp;<a href="https://doc.rust-lang.org/1.64.0/std/primitive.str.html" title="str">str</a></code> is to <code>String</code>: the former
in each pair are borrowed references; the latter are owned
strings.</p>
<p>Note that this structure is <strong>not</strong> <code>repr(C)</code> and is not recommended to be
placed in the signatures of FFI functions. Instead, safe wrappers of FFI
functions may leverage the unsafe <a href="struct.CStr.html#method.from_ptr" title="CStr::from_ptr"><code>CStr::from_ptr</code></a> constructor to provide
a safe interface to other consumers.</p>
<h2 id="examples"><a href="#examples">Examples</a></h2>
<p>Inspecting a foreign C string:</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::CStr</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_string</span>() -&gt; <span class="kw-2">*const</span> <span class="ident">c_char</span>; }
<span class="kw">unsafe</span> {
<span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> <span class="ident">CStr::from_ptr</span>(<span class="ident">my_string</span>());
<span class="macro">println!</span>(<span class="string">&quot;string buffer size without nul terminator: {}&quot;</span>, <span class="ident">slice</span>.<span class="ident">to_bytes</span>().<span class="ident">len</span>());
}</code></pre></div>
<p>Passing a Rust-originating C string:</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</span>::{<span class="ident">CString</span>, <span class="ident">CStr</span>};
<span class="kw">use</span> <span class="ident">std::os::raw::c_char</span>;
<span class="kw">fn</span> <span class="ident">work</span>(<span class="ident">data</span>: <span class="kw-2">&amp;</span><span class="ident">CStr</span>) {
<span class="kw">extern</span> <span class="string">&quot;C&quot;</span> { <span class="kw">fn</span> <span class="ident">work_with</span>(<span class="ident">data</span>: <span class="kw-2">*const</span> <span class="ident">c_char</span>); }
<span class="kw">unsafe</span> { <span class="ident">work_with</span>(<span class="ident">data</span>.<span class="ident">as_ptr</span>()) }
}
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">CString::new</span>(<span class="string">&quot;data data data data&quot;</span>).<span class="ident">expect</span>(<span class="string">&quot;CString::new failed&quot;</span>);
<span class="ident">work</span>(<span class="kw-2">&amp;</span><span class="ident">s</span>);</code></pre></div>
<p>Converting a foreign C string into a Rust <code>String</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::CStr</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_string</span>() -&gt; <span class="kw-2">*const</span> <span class="ident">c_char</span>; }
<span class="kw">fn</span> <span class="ident">my_string_safe</span>() -&gt; <span class="ident">String</span> {
<span class="kw">let</span> <span class="ident">cstr</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="ident">CStr::from_ptr</span>(<span class="ident">my_string</span>()) };
<span class="comment">// Get copy-on-write Cow&lt;&#39;_, str&gt;, then guarantee a freshly-owned String allocation</span>
<span class="ident">String::from_utf8_lossy</span>(<span class="ident">cstr</span>.<span class="ident">to_bytes</span>()).<span class="ident">to_string</span>()
}
<span class="macro">println!</span>(<span class="string">&quot;string: {}&quot;</span>, <span class="ident">my_string_safe</span>());</code></pre></div>
</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-CStr" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/ffi/c_str.rs.html#193">source</a></span><a href="#impl-CStr" class="anchor"></a><h3 class="code-header in-band">impl <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_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#248">source</a></span><h4 class="code-header">pub unsafe fn <a href="#method.from_ptr" class="fnname">from_ptr</a>&lt;'a&gt;(ptr: <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>) -&gt; &amp;'a <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h4></section></summary><div class="docblock"><p>Wraps a raw C string with a safe C string wrapper.</p>
<p>This function will wrap the provided <code>ptr</code> with a <code>CStr</code> wrapper, which
allows inspection and interoperation of non-owned C strings. The total
size of the raw C string must be smaller than <code>isize::MAX</code> <strong>bytes</strong>
in memory due to calling the <code>slice::from_raw_parts</code> function.</p>
<h5 id="safety"><a href="#safety">Safety</a></h5>
<ul>
<li>
<p>The memory pointed to by <code>ptr</code> must contain a valid nul terminator at the
end of the string.</p>
</li>
<li>
<p><code>ptr</code> must be <a href="https://doc.rust-lang.org/1.64.0/core/ptr/index.html#safety">valid</a> for reads of bytes up to and including the null terminator.
This means in particular:</p>
<ul>
<li>The entire memory range of this <code>CStr</code> must be contained within a single allocated object!</li>
<li><code>ptr</code> must be non-null even for a zero-length cstr.</li>
</ul>
</li>
<li>
<p>The memory referenced by the returned <code>CStr</code> must not be mutated for
the duration of lifetime <code>'a</code>.</p>
</li>
</ul>
<blockquote>
<p><strong>Note</strong>: This operation is intended to be a 0-cost cast but it is
currently implemented with an up-front calculation of the length of
the string. This is not guaranteed to always be the case.</p>
</blockquote>
<h5 id="caveat"><a href="#caveat">Caveat</a></h5>
<p>The lifetime for the returned slice is inferred from its usage. To prevent accidental misuse,
its suggested to tie the lifetime to whichever source lifetime is safe in the context,
such as by providing a helper function taking the lifetime of a host value for the slice,
or by explicit annotation.</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::CStr</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_string</span>() -&gt; <span class="kw-2">*const</span> <span class="ident">c_char</span>;
}
<span class="kw">unsafe</span> {
<span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> <span class="ident">CStr::from_ptr</span>(<span class="ident">my_string</span>());
<span class="macro">println!</span>(<span class="string">&quot;string returned: {}&quot;</span>, <span class="ident">slice</span>.<span class="ident">to_str</span>().<span class="ident">unwrap</span>());
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_bytes_until_nul" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/ffi/c_str.rs.html#302">source</a></span><h4 class="code-header">pub fn <a href="#method.from_bytes_until_nul" class="fnname">from_bytes_until_nul</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;bytes: &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>]<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;&amp;<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/core/ffi/c_str/struct.FromBytesUntilNulError.html" title="struct core::ffi::c_str::FromBytesUntilNulError">FromBytesUntilNulError</a>&gt;</h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>cstr_from_bytes_until_nul</code>)</div></span></summary><div class="docblock"><p>Creates a C string wrapper from a byte slice.</p>
<p>This method will create a <code>CStr</code> from any byte slice that contains at
least one nul byte. The caller does not need to know or specify where
the nul byte is located.</p>
<p>If the first byte is a nul character, this method will return an
empty <code>CStr</code>. If multiple nul characters are present, the <code>CStr</code> will
end at the first one.</p>
<p>If the slice only has a single nul byte at the end, this method is
equivalent to <a href="struct.CStr.html#method.from_bytes_with_nul" title="CStr::from_bytes_with_nul"><code>CStr::from_bytes_with_nul</code></a>.</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="attribute">#![<span class="ident">feature</span>(<span class="ident">cstr_from_bytes_until_nul</span>)]</span>
<span class="kw">use</span> <span class="ident">std::ffi::CStr</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">buffer</span> <span class="op">=</span> [<span class="number">0u8</span>; <span class="number">16</span>];
<span class="kw">unsafe</span> {
<span class="comment">// Here we might call an unsafe C function that writes a string</span>
<span class="comment">// into the buffer.</span>
<span class="kw">let</span> <span class="ident">buf_ptr</span> <span class="op">=</span> <span class="ident">buffer</span>.<span class="ident">as_mut_ptr</span>();
<span class="ident">buf_ptr</span>.<span class="ident">write_bytes</span>(<span class="string">b&#39;A&#39;</span>, <span class="number">8</span>);
}
<span class="comment">// Attempt to extract a C nul-terminated string from the buffer.</span>
<span class="kw">let</span> <span class="ident">c_str</span> <span class="op">=</span> <span class="ident">CStr::from_bytes_until_nul</span>(<span class="kw-2">&amp;</span><span class="ident">buffer</span>[..]).<span class="ident">unwrap</span>();
<span class="macro">assert_eq!</span>(<span class="ident">c_str</span>.<span class="ident">to_str</span>().<span class="ident">unwrap</span>(), <span class="string">&quot;AAAAAAAA&quot;</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_bytes_with_nul" class="method 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/core/ffi/c_str.rs.html#351">source</a></span><h4 class="code-header">pub fn <a href="#method.from_bytes_with_nul" class="fnname">from_bytes_with_nul</a>(bytes: &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>]) -&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="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>, <a class="struct" href="struct.FromBytesWithNulError.html" title="struct rustix::ffi::FromBytesWithNulError">FromBytesWithNulError</a>&gt;</h4></section></summary><div class="docblock"><p>Creates a C string wrapper from a byte slice.</p>
<p>This function will cast the provided <code>bytes</code> to a <code>CStr</code>
wrapper after ensuring that the byte slice is nul-terminated
and does not contain any interior nul bytes.</p>
<p>If the nul byte may not be at the end,
<a href="struct.CStr.html#method.from_bytes_until_nul" title="CStr::from_bytes_until_nul"><code>CStr::from_bytes_until_nul</code></a> can be used instead.</p>
<h5 id="examples-3"><a href="#examples-3">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;hello\0&quot;</span>);
<span class="macro">assert!</span>(<span class="ident">cstr</span>.<span class="ident">is_ok</span>());</code></pre></div>
<p>Creating a <code>CStr</code> without a trailing nul terminator is an error:</p>
<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;hello&quot;</span>);
<span class="macro">assert!</span>(<span class="ident">cstr</span>.<span class="ident">is_err</span>());</code></pre></div>
<p>Creating a <code>CStr</code> with an interior nul byte is an error:</p>
<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;he\0llo\0&quot;</span>);
<span class="macro">assert!</span>(<span class="ident">cstr</span>.<span class="ident">is_err</span>());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_bytes_with_nul_unchecked" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.10.0, const since 1.59.0">1.10.0 (const: 1.59.0)</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/ffi/c_str.rs.html#389">source</a></span><h4 class="code-header">pub const unsafe fn <a href="#method.from_bytes_with_nul_unchecked" class="fnname">from_bytes_with_nul_unchecked</a>(bytes: &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.u8.html">u8</a>]) -&gt; &amp;<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h4></section></summary><div class="docblock"><p>Unsafely creates a C string wrapper from a byte slice.</p>
<p>This function will cast the provided <code>bytes</code> to a <code>CStr</code> wrapper without
performing any sanity checks.</p>
<h5 id="safety-1"><a href="#safety-1">Safety</a></h5>
<p>The provided slice <strong>must</strong> be nul-terminated and not contain any interior
nul bytes.</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</span>::{<span class="ident">CStr</span>, <span class="ident">CString</span>};
<span class="kw">unsafe</span> {
<span class="kw">let</span> <span class="ident">cstring</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">cstr</span> <span class="op">=</span> <span class="ident">CStr::from_bytes_with_nul_unchecked</span>(<span class="ident">cstring</span>.<span class="ident">to_bytes_with_nul</span>());
<span class="macro">assert_eq!</span>(<span class="ident">cstr</span>, <span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">cstring</span>);
}</code></pre></div>
</div></details><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, const since 1.32.0">1.0.0 (const: 1.32.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 const 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-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::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-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::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-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::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></details></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-CStr" 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/core/ffi/c_str.rs.html#603">source</a></span><a href="#impl-AsRef%3CCStr%3E-for-CStr" 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.CStr.html" title="struct rustix::ffi::CStr">CStr</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/core/ffi/c_str.rs.html#605">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-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-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#1051">source</a></span><a href="#method.as_ref-1" 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-Debug-for-CStr" 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/core/ffi/c_str.rs.html#162">source</a></span><a href="#impl-Debug-for-CStr" 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.CStr.html" title="struct rustix::ffi::CStr">CStr</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/core/ffi/c_str.rs.html#163">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-%26CStr" 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/core/ffi/c_str.rs.html#173">source</a></span><a href="#impl-Default-for-%26CStr" 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 &amp;<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</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/core/ffi/c_str.rs.html#174">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; &amp;<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h4></section></summary><div class='docblock'><p>Returns the “default value” for a type. <a href="https://doc.rust-lang.org/1.64.0/core/default/trait.Default.html#tymethod.default">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" 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" 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-Hash-for-CStr" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/ffi/c_str.rs.html#78">source</a></span><a href="#impl-Hash-for-CStr" 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.CStr.html" title="struct rustix::ffi::CStr">CStr</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/core/ffi/c_str.rs.html#78">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%3CRangeFrom%3Cusize%3E%3E-for-CStr" class="impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.47.0">1.47.0</span> · <a class="srclink" href="https://doc.rust-lang.org/1.64.0/src/core/ffi/c_str.rs.html#581">source</a></span><a href="#impl-Index%3CRangeFrom%3Cusize%3E%3E-for-CStr" 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.RangeFrom.html" title="struct core::ops::range::RangeFrom">RangeFrom</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.usize.html">usize</a>&gt;&gt; for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</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/core/ffi/c_str.rs.html#584">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.RangeFrom.html" title="struct core::ops::range::RangeFrom">RangeFrom</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.64.0/std/primitive.usize.html">usize</a>&gt;) -&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-CStr" 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/core/ffi/c_str.rs.html#574">source</a></span><a href="#impl-Ord-for-CStr" 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.CStr.html" title="struct rustix::ffi::CStr">CStr</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/core/ffi/c_str.rs.html#575">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.CStr.html" title="struct rustix::ffi::CStr">CStr</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%3CCStr%3E-for-CStr" 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/core/ffi/c_str.rs.html#560">source</a></span><a href="#impl-PartialEq%3CCStr%3E-for-CStr" 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.CStr.html" title="struct rustix::ffi::CStr">CStr</a>&gt; for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</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/core/ffi/c_str.rs.html#561">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.CStr.html" title="struct rustix::ffi::CStr">CStr</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"><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#232">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: <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 for <code>!=</code>.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-PartialOrd%3CCStr%3E-for-CStr" 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/core/ffi/c_str.rs.html#568">source</a></span><a href="#impl-PartialOrd%3CCStr%3E-for-CStr" 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.CStr.html" title="struct rustix::ffi::CStr">CStr</a>&gt; for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</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/core/ffi/c_str.rs.html#569">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.CStr.html" title="struct rustix::ffi::CStr">CStr</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><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-ToOwned-for-CStr" 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#1017">source</a></span><a href="#impl-ToOwned-for-CStr" class="anchor"></a><h3 class="code-header in-band">impl <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 <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></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> = <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></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/ffi/c_str.rs.html#1020">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; <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></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/ffi/c_str.rs.html#1024">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: &amp;mut <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a>)</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><section id="impl-Eq-for-CStr" 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/core/ffi/c_str.rs.html#566">source</a></span><a href="#impl-Eq-for-CStr" 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.CStr.html" title="struct rustix::ffi::CStr">CStr</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-CStr" class="impl has-srclink"><a href="#impl-RefUnwindSafe-for-CStr" 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.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section><section id="impl-Send-for-CStr" class="impl has-srclink"><a href="#impl-Send-for-CStr" 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.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section><section id="impl-Sized-for-CStr" class="impl has-srclink"><a href="#impl-Sized-for-CStr" 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.Sized.html" title="trait core::marker::Sized">Sized</a> for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section><section id="impl-Sync-for-CStr" class="impl has-srclink"><a href="#impl-Sync-for-CStr" 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.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section><section id="impl-Unpin-for-CStr" class="impl has-srclink"><a href="#impl-Unpin-for-CStr" 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.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section><section id="impl-UnwindSafe-for-CStr" class="impl has-srclink"><a href="#impl-UnwindSafe-for-CStr" 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.CStr.html" title="struct rustix::ffi::CStr">CStr</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-CStr" 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-CStr" 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-CStr" 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-CStr" 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-CStr" 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-CStr" 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></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>