mpvrc/rustix/ffi/struct.CStr.html

326 lines
No EOL
80 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."><title>CStr in rustix::ffi - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="rustix" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../rustix/index.html">rustix</a><span class="version">0.38.42</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">CStr</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li></ul><h3><a href="#implementations">Methods</a></h3><ul class="block method"><li><a href="#method.as_ptr" title="as_ptr">as_ptr</a></li><li><a href="#method.bytes" title="bytes">bytes</a></li><li><a href="#method.count_bytes" title="count_bytes">count_bytes</a></li><li><a href="#method.from_bytes_until_nul" title="from_bytes_until_nul">from_bytes_until_nul</a></li><li><a href="#method.from_bytes_with_nul" title="from_bytes_with_nul">from_bytes_with_nul</a></li><li><a href="#method.from_bytes_with_nul_unchecked" title="from_bytes_with_nul_unchecked">from_bytes_with_nul_unchecked</a></li><li><a href="#method.from_ptr" title="from_ptr">from_ptr</a></li><li><a href="#method.into_c_string" title="into_c_string">into_c_string</a></li><li><a href="#method.is_empty" title="is_empty">is_empty</a></li><li><a href="#method.to_bytes" title="to_bytes">to_bytes</a></li><li><a href="#method.to_bytes_with_nul" title="to_bytes_with_nul">to_bytes_with_nul</a></li><li><a href="#method.to_str" title="to_str">to_str</a></li><li><a href="#method.to_string_lossy" title="to_string_lossy">to_string_lossy</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-Arg-for-%26CStr" title="Arg">Arg</a></li><li><a href="#impl-AsRef%3CCStr%3E-for-CStr" title="AsRef&#60;CStr&#62;">AsRef&#60;CStr&#62;</a></li><li><a href="#impl-AsRef%3CCStr%3E-for-CString" title="AsRef&#60;CStr&#62;">AsRef&#60;CStr&#62;</a></li><li><a href="#impl-Borrow%3CCStr%3E-for-CString" title="Borrow&#60;CStr&#62;">Borrow&#60;CStr&#62;</a></li><li><a href="#impl-CloneToUninit-for-CStr" title="CloneToUninit">CloneToUninit</a></li><li><a href="#impl-Debug-for-CStr" title="Debug">Debug</a></li><li><a href="#impl-Default-for-%26CStr" title="Default">Default</a></li><li><a href="#impl-Eq-for-CStr" title="Eq">Eq</a></li><li><a href="#impl-From%3C%26CStr%3E-for-CString" title="From&#60;&#38;CStr&#62;">From&#60;&#38;CStr&#62;</a></li><li><a href="#impl-Hash-for-CStr" title="Hash">Hash</a></li><li><a href="#impl-Index%3CRangeFrom%3Cusize%3E%3E-for-CStr" title="Index&#60;RangeFrom&#60;usize&#62;&#62;">Index&#60;RangeFrom&#60;usize&#62;&#62;</a></li><li><a href="#impl-Ord-for-CStr" title="Ord">Ord</a></li><li><a href="#impl-PartialEq-for-CStr" title="PartialEq">PartialEq</a></li><li><a href="#impl-PartialOrd-for-CStr" title="PartialOrd">PartialOrd</a></li><li><a href="#impl-StructuralPartialEq-for-CStr" title="StructuralPartialEq">StructuralPartialEq</a></li><li><a href="#impl-ToOwned-for-CStr" title="ToOwned">ToOwned</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-Sized-for-CStr" title="!Sized">!Sized</a></li><li><a href="#impl-Freeze-for-CStr" title="Freeze">Freeze</a></li><li><a href="#impl-RefUnwindSafe-for-CStr" title="RefUnwindSafe">RefUnwindSafe</a></li><li><a href="#impl-Send-for-CStr" title="Send">Send</a></li><li><a href="#impl-Sync-for-CStr" title="Sync">Sync</a></li><li><a href="#impl-Unpin-for-CStr" title="Unpin">Unpin</a></li><li><a href="#impl-UnwindSafe-for-CStr" title="UnwindSafe">UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block blanket-implementation"><li><a href="#impl-Any-for-T" title="Any">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-T" title="Borrow&#60;T&#62;">Borrow&#60;T&#62;</a></li><li><a href="#impl-BorrowMut%3CT%3E-for-T" title="BorrowMut&#60;T&#62;">BorrowMut&#60;T&#62;</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In rustix::<wbr>ffi</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">rustix</a>::<wbr><a href="index.html">ffi</a></span><h1>Struct <span class="struct">CStr</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><span class="since" title="Stable since Rust version 1.64.0">1.64.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#104">Source</a> </span></div><pre class="rust item-decl"><code>pub struct CStr { <span class="comment">/* private fields */</span> }</code></pre><details class="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.84.1/std/primitive.u8.html" title="primitive u8">u8</a>]</code>
slice, or unsafely from a raw <code>*const c_char</code>. It can be expressed as a
literal in the form <code>c"Hello world"</code>.</p>
<p>The <code>CStr</code> can then be converted to a Rust <code>&amp;<a href="https://doc.rust-lang.org/1.84.1/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.84.1/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 does <strong>not</strong> have a guaranteed layout (the <code>repr(transparent)</code>
notwithstanding) and should not be placed in the signatures of FFI functions.
Instead, safe wrappers of FFI functions may leverage <a href="struct.CStr.html#method.as_ptr" title="method rustix::ffi::CStr::as_ptr"><code>CStr::as_ptr</code></a> and the unsafe
<a href="struct.CStr.html#method.from_ptr" title="associated function rustix::ffi::CStr::from_ptr"><code>CStr::from_ptr</code></a> constructor to provide a safe interface to other consumers.</p>
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
<p>Inspecting a foreign C string:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CStr;
<span class="kw">use </span>std::os::raw::c_char;
<span class="kw">extern </span><span class="string">"C" </span>{ <span class="kw">fn </span>my_string() -&gt; <span class="kw-2">*const </span>c_char; }
<span class="kw">unsafe </span>{
<span class="kw">let </span>slice = CStr::from_ptr(my_string());
<span class="macro">println!</span>(<span class="string">"string buffer size without nul terminator: {}"</span>, slice.to_bytes().len());
}</code></pre></div>
<p>Passing a Rust-originating C string:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::{CString, CStr};
<span class="kw">use </span>std::os::raw::c_char;
<span class="kw">fn </span>work(data: <span class="kw-2">&amp;</span>CStr) {
<span class="kw">extern </span><span class="string">"C" </span>{ <span class="kw">fn </span>work_with(data: <span class="kw-2">*const </span>c_char); }
<span class="kw">unsafe </span>{ work_with(data.as_ptr()) }
}
<span class="kw">let </span>s = CString::new(<span class="string">"data data data data"</span>).expect(<span class="string">"CString::new failed"</span>);
work(<span class="kw-2">&amp;</span>s);</code></pre></div>
<p>Converting a foreign C string into a Rust <code>String</code>:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CStr;
<span class="kw">use </span>std::os::raw::c_char;
<span class="kw">extern </span><span class="string">"C" </span>{ <span class="kw">fn </span>my_string() -&gt; <span class="kw-2">*const </span>c_char; }
<span class="kw">fn </span>my_string_safe() -&gt; String {
<span class="kw">let </span>cstr = <span class="kw">unsafe </span>{ CStr::from_ptr(my_string()) };
<span class="comment">// Get copy-on-write Cow&lt;'_, str&gt;, then guarantee a freshly-owned String allocation
</span>String::from_utf8_lossy(cstr.to_bytes()).to_string()
}
<span class="macro">println!</span>(<span class="string">"string: {}"</span>, my_string_safe());</code></pre></div>
</div></details><h2 id="implementations" class="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-CStr" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#211">Source</a><a href="#impl-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from_ptr" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0, const since 1.81.0">1.0.0 (const: 1.81.0)</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#278">Source</a></span><h4 class="code-header">pub const unsafe fn <a href="#method.from_ptr" class="fn">from_ptr</a>&lt;'a&gt;(ptr: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.pointer.html">*const </a><a class="primitive" href="https://doc.rust-lang.org/1.84.1/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 terminated buffer must be smaller than <a href="https://doc.rust-lang.org/1.84.1/std/primitive.isize.html#associatedconstant.MAX" title="associated constant isize::MAX"><code>isize::MAX</code></a> <strong>bytes</strong>
in memory (a restriction from <a href="https://doc.rust-lang.org/1.84.1/core/slice/raw/fn.from_raw_parts.html" title="fn core::slice::raw::from_raw_parts"><code>slice::from_raw_parts</code></a>).</p>
<h5 id="safety"><a class="doc-anchor" href="#safety">§</a>Safety</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.84.1/core/ptr/index.html#safety" title="mod core::ptr">valid</a> for reads of bytes up to and including the nul 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>
<li>
<p>The nul terminator must be within <code>isize::MAX</code> from <code>ptr</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 class="doc-anchor" href="#caveat">§</a>Caveat</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 class="doc-anchor" href="#examples-1">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::{c_char, CStr};
<span class="kw">fn </span>my_string() -&gt; <span class="kw-2">*const </span>c_char {
<span class="string">c"hello"</span>.as_ptr()
}
<span class="kw">unsafe </span>{
<span class="kw">let </span>slice = CStr::from_ptr(my_string());
<span class="macro">assert_eq!</span>(slice.to_str().unwrap(), <span class="string">"hello"</span>);
}</code></pre></div>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::{c_char, CStr};
<span class="kw">const </span>HELLO_PTR: <span class="kw-2">*const </span>c_char = {
<span class="kw">const </span>BYTES: <span class="kw-2">&amp;</span>[u8] = <span class="string">b"Hello, world!\0"</span>;
BYTES.as_ptr().cast()
};
<span class="kw">const </span>HELLO: <span class="kw-2">&amp;</span>CStr = <span class="kw">unsafe </span>{ CStr::from_ptr(HELLO_PTR) };
<span class="macro">assert_eq!</span>(<span class="string">c"Hello, world!"</span>, HELLO);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.from_bytes_until_nul" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.69.0, const since 1.69.0">1.69.0 (const: 1.69.0)</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#323">Source</a></span><h4 class="code-header">pub const fn <a href="#method.from_bytes_until_nul" class="fn">from_bytes_until_nul</a>(
bytes: &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u8.html">u8</a>],
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/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.84.1/core/ffi/c_str/struct.FromBytesUntilNulError.html" title="struct core::ffi::c_str::FromBytesUntilNulError">FromBytesUntilNulError</a>&gt;</h4></section></summary><div class="docblock"><p>Creates a C string wrapper from a byte slice with any number of nuls.</p>
<p>This method will create a <code>CStr</code> from any byte slice that contains at
least one nul byte. Unlike with <a href="struct.CStr.html#method.from_bytes_with_nul" title="associated function rustix::ffi::CStr::from_bytes_with_nul"><code>CStr::from_bytes_with_nul</code></a>, the caller
does not need to know 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="associated function rustix::ffi::CStr::from_bytes_with_nul"><code>CStr::from_bytes_with_nul</code></a>.</p>
<h5 id="examples-2"><a class="doc-anchor" href="#examples-2">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CStr;
<span class="kw">let </span><span class="kw-2">mut </span>buffer = [<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
// into the buffer.
</span><span class="kw">let </span>buf_ptr = buffer.as_mut_ptr();
buf_ptr.write_bytes(<span class="string">b'A'</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>c_str = CStr::from_bytes_until_nul(<span class="kw-2">&amp;</span>buffer[..]).unwrap();
<span class="macro">assert_eq!</span>(c_str.to_str().unwrap(), <span class="string">"AAAAAAAA"</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.from_bytes_with_nul" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.10.0, const since 1.72.0">1.10.0 (const: 1.72.0)</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#376">Source</a></span><h4 class="code-header">pub const fn <a href="#method.from_bytes_with_nul" class="fn">from_bytes_with_nul</a>(
bytes: &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u8.html">u8</a>],
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/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 with exactly one nul
terminator.</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="associated function rustix::ffi::CStr::from_bytes_until_nul"><code>CStr::from_bytes_until_nul</code></a> can be used instead.</p>
<h5 id="examples-3"><a class="doc-anchor" href="#examples-3">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CStr;
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"hello\0"</span>);
<span class="macro">assert!</span>(cstr.is_ok());</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>std::ffi::CStr;
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"hello"</span>);
<span class="macro">assert!</span>(cstr.is_err());</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>std::ffi::CStr;
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"he\0llo\0"</span>);
<span class="macro">assert!</span>(cstr.is_err());</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.from_bytes_with_nul_unchecked" class="method"><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="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#414">Source</a></span><h4 class="code-header">pub const unsafe fn <a href="#method.from_bytes_with_nul_unchecked" class="fn">from_bytes_with_nul_unchecked</a>(bytes: &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.84.1/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 class="doc-anchor" href="#safety-1">§</a>Safety</h5>
<p>The provided slice <strong>must</strong> be nul-terminated and not contain any interior
nul bytes.</p>
<h5 id="examples-4"><a class="doc-anchor" href="#examples-4">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::{CStr, CString};
<span class="kw">unsafe </span>{
<span class="kw">let </span>cstring = CString::new(<span class="string">"hello"</span>).expect(<span class="string">"CString::new failed"</span>);
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul_unchecked(cstring.to_bytes_with_nul());
<span class="macro">assert_eq!</span>(cstr, <span class="kw-2">&amp;*</span>cstring);
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.as_ptr" class="method"><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="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#505">Source</a></span><h4 class="code-header">pub const fn <a href="#method.as_ptr" class="fn">as_ptr</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.pointer.html">*const </a><a class="primitive" href="https://doc.rust-lang.org/1.84.1/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>The type of the returned pointer is
<a href="https://doc.rust-lang.org/1.84.1/core/ffi/type.c_char.html" title="type core::ffi::c_char"><code>*const c_char</code></a>, and whether its
an alias for <code>*const i8</code> or <code>*const u8</code> is platform-specific.</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>std::ffi::CString;
<span class="comment">// Do not do this:
</span><span class="kw">let </span>ptr = CString::new(<span class="string">"Hello"</span>).expect(<span class="string">"CString::new failed"</span>).as_ptr();
<span class="kw">unsafe </span>{
<span class="comment">// `ptr` is dangling
</span><span class="kw-2">*</span>ptr;
}</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("Hello").expect("CString::new failed").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>std::ffi::CString;
<span class="kw">let </span>hello = CString::new(<span class="string">"Hello"</span>).expect(<span class="string">"CString::new failed"</span>);
<span class="kw">let </span>ptr = hello.as_ptr();
<span class="kw">unsafe </span>{
<span class="comment">// `ptr` is valid because `hello` is in scope
</span><span class="kw-2">*</span>ptr;
}</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="toggle method-toggle" open><summary><section id="method.count_bytes" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.79.0, const since 1.81.0">1.79.0 (const: 1.81.0)</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#541">Source</a></span><h4 class="code-header">pub const fn <a href="#method.count_bytes" class="fn">count_bytes</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Returns the length of <code>self</code>. Like Cs <code>strlen</code>, this does not include the nul terminator.</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 class="doc-anchor" href="#examples-5">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CStr;
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"foo\0"</span>).unwrap();
<span class="macro">assert_eq!</span>(cstr.count_bytes(), <span class="number">3</span>);
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"\0"</span>).unwrap();
<span class="macro">assert_eq!</span>(cstr.count_bytes(), <span class="number">0</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.is_empty" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.71.0, const since 1.71.0">1.71.0 (const: 1.71.0)</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#567">Source</a></span><h4 class="code-header">pub const fn <a href="#method.is_empty" class="fn">is_empty</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if <code>self.to_bytes()</code> has a length of 0.</p>
<h5 id="examples-6"><a class="doc-anchor" href="#examples-6">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CStr;
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"foo\0"</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(!cstr.is_empty());
<span class="kw">let </span>empty_cstr = CStr::from_bytes_with_nul(<span class="string">b"\0"</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(empty_cstr.is_empty());
<span class="macro">assert!</span>(<span class="string">c""</span>.is_empty());</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.to_bytes" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0, const since 1.72.0">1.0.0 (const: 1.72.0)</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#596">Source</a></span><h4 class="code-header">pub const fn <a href="#method.to_bytes" class="fn">to_bytes</a>(&amp;self) -&gt; &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u8.html">u8</a>] <a href="#" class="tooltip" data-notable-ty="&amp;[u8]"></a></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-7"><a class="doc-anchor" href="#examples-7">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CStr;
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"foo\0"</span>).expect(<span class="string">"CStr::from_bytes_with_nul failed"</span>);
<span class="macro">assert_eq!</span>(cstr.to_bytes(), <span class="string">b"foo"</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.to_bytes_with_nul" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0, const since 1.72.0">1.0.0 (const: 1.72.0)</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#625">Source</a></span><h4 class="code-header">pub const fn <a href="#method.to_bytes_with_nul" class="fn">to_bytes_with_nul</a>(&amp;self) -&gt; &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u8.html">u8</a>] <a href="#" class="tooltip" data-notable-ty="&amp;[u8]"></a></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="method rustix::ffi::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-8"><a class="doc-anchor" href="#examples-8">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CStr;
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"foo\0"</span>).expect(<span class="string">"CStr::from_bytes_with_nul failed"</span>);
<span class="macro">assert_eq!</span>(cstr.to_bytes_with_nul(), <span class="string">b"foo\0"</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.bytes" class="method"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#647">Source</a><h4 class="code-header">pub fn <a href="#method.bytes" class="fn">bytes</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.84.1/core/ffi/c_str/struct.Bytes.html" title="struct core::ffi::c_str::Bytes">Bytes</a>&lt;'_&gt;</h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span><span>This is a nightly-only experimental API. (<code>cstr_bytes</code>)</span></div></span></summary><div class="docblock"><p>Iterates over the bytes in this C string.</p>
<p>The returned iterator will <strong>not</strong> contain the trailing nul terminator
that this C string has.</p>
<h5 id="examples-9"><a class="doc-anchor" href="#examples-9">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#![feature(cstr_bytes)]
</span><span class="kw">use </span>std::ffi::CStr;
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"foo\0"</span>).expect(<span class="string">"CStr::from_bytes_with_nul failed"</span>);
<span class="macro">assert!</span>(cstr.bytes().eq(<span class="kw-2">*</span><span class="string">b"foo"</span>));</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.to_str" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.4.0, const since 1.72.0">1.4.0 (const: 1.72.0)</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#669">Source</a></span><h4 class="code-header">pub const fn <a href="#method.to_str" class="fn">to_str</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;&amp;<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.str.html">str</a>, <a class="struct" href="https://doc.rust-lang.org/1.84.1/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.84.1/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.84.1/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-10"><a class="doc-anchor" href="#examples-10">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CStr;
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"foo\0"</span>).expect(<span class="string">"CStr::from_bytes_with_nul failed"</span>);
<span class="macro">assert_eq!</span>(cstr.to_str(), <span class="prelude-val">Ok</span>(<span class="string">"foo"</span>));</code></pre></div>
</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-CStr-1" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/alloc/ffi/c_str.rs.html#1122">Source</a><a href="#impl-CStr-1" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.to_string_lossy" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.4.0">1.4.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/alloc/ffi/c_str.rs.html#1162">Source</a></span><h4 class="code-header">pub fn <a href="#method.to_string_lossy" class="fn">to_string_lossy</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a>&lt;'_, <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.str.html">str</a>&gt;</h4></section></summary><div class="docblock"><p>Converts a <code>CStr</code> into a <code><a href="https://doc.rust-lang.org/1.84.1/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a>&lt;<a href="https://doc.rust-lang.org/1.84.1/std/primitive.str.html" title="str">str</a>&gt;</code>.</p>
<p>If the contents of the <code>CStr</code> are valid UTF-8 data, this
function will return a <code><a href="https://doc.rust-lang.org/1.84.1/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a>::<a href="https://doc.rust-lang.org/1.84.1/alloc/borrow/enum.Cow.html#variant.Borrowed" title="variant alloc::borrow::Cow::Borrowed">Borrowed</a>(&amp;<a href="https://doc.rust-lang.org/1.84.1/std/primitive.str.html" title="str">str</a>)</code>
with the corresponding <code>&amp;<a href="https://doc.rust-lang.org/1.84.1/std/primitive.str.html" title="str">str</a></code> slice. Otherwise, it will
replace any invalid UTF-8 sequences with
<a href="https://doc.rust-lang.org/1.84.1/core/char/constant.REPLACEMENT_CHARACTER.html" title="std::char::REPLACEMENT_CHARACTER"><code>U+FFFD REPLACEMENT CHARACTER</code></a> and return a
<code><a href="https://doc.rust-lang.org/1.84.1/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a>::<a href="https://doc.rust-lang.org/1.84.1/alloc/borrow/enum.Cow.html#variant.Owned" title="variant alloc::borrow::Cow::Owned">Owned</a>(&amp;<a href="https://doc.rust-lang.org/1.84.1/std/primitive.str.html" title="str">str</a>)</code> with the result.</p>
<h5 id="examples-11"><a class="doc-anchor" href="#examples-11">§</a>Examples</h5>
<p>Calling <code>to_string_lossy</code> on a <code>CStr</code> containing valid UTF-8. The leading
<code>c</code> on the string literal denotes a <code>CStr</code>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::borrow::Cow;
<span class="macro">assert_eq!</span>(<span class="string">c"Hello World"</span>.to_string_lossy(), Cow::Borrowed(<span class="string">"Hello World"</span>));</code></pre></div>
<p>Calling <code>to_string_lossy</code> on a <code>CStr</code> containing invalid UTF-8:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::borrow::Cow;
<span class="macro">assert_eq!</span>(
<span class="string">c"Hello \xF0\x90\x80World"</span>.to_string_lossy(),
Cow::Owned(String::from(<span class="string">"Hello <20>World"</span>)) <span class="kw">as </span>Cow&lt;<span class="lifetime">'_</span>, str&gt;
);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.into_c_string" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.20.0">1.20.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/alloc/ffi/c_str.rs.html#1180">Source</a></span><h4 class="code-header">pub fn <a href="#method.into_c_string" class="fn">into_c_string</a>(self: <a class="struct" href="https://doc.rust-lang.org/1.84.1/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>&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.84.1/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;<a href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>&gt;</code> into a <a href="struct.CString.html" title="struct rustix::ffi::CString"><code>CString</code></a> without copying or allocating.</p>
<h5 id="examples-12"><a class="doc-anchor" href="#examples-12">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CString;
<span class="kw">let </span>c_string = CString::new(<span class="string">b"foo"</span>.to_vec()).expect(<span class="string">"CString::new failed"</span>);
<span class="kw">let </span>boxed = c_string.into_boxed_c_str();
<span class="macro">assert_eq!</span>(boxed.into_c_string(), CString::new(<span class="string">"foo"</span>).expect(<span class="string">"CString::new failed"</span>));</code></pre></div>
</div></details></div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Arg-for-%26CStr" class="impl"><a class="src rightside" href="../../src/rustix/path/arg.rs.html#485-520">Source</a><a href="#impl-Arg-for-%26CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="../path/trait.Arg.html" title="trait rustix::path::Arg">Arg</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="toggle method-toggle" open><summary><section id="method.as_str" class="method trait-impl"><a class="src rightside" href="../../src/rustix/path/arg.rs.html#487-489">Source</a><a href="#method.as_str" class="anchor">§</a><h4 class="code-header">fn <a href="../path/trait.Arg.html#tymethod.as_str" class="fn">as_str</a>(&amp;self) -&gt; <a class="type" href="../io/type.Result.html" title="type rustix::io::Result">Result</a>&lt;&amp;<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.str.html">str</a>&gt;</h4></section></summary><div class='docblock'>Returns a view of this string as a string slice.</div></details><details class="toggle method-toggle" open><summary><section id="method.to_string_lossy-1" class="method trait-impl"><a class="src rightside" href="../../src/rustix/path/arg.rs.html#493-495">Source</a><a href="#method.to_string_lossy-1" class="anchor">§</a><h4 class="code-header">fn <a href="../path/trait.Arg.html#tymethod.to_string_lossy" class="fn">to_string_lossy</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a>&lt;'_, <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.str.html">str</a>&gt;</h4></section></summary><div class='docblock'>Returns a potentially-lossy rendering of this string as a
<code>Cow&lt;'_, str&gt;</code>.</div></details><details class="toggle method-toggle" open><summary><section id="method.as_cow_c_str" class="method trait-impl"><a class="src rightside" href="../../src/rustix/path/arg.rs.html#499-501">Source</a><a href="#method.as_cow_c_str" class="anchor">§</a><h4 class="code-header">fn <a href="../path/trait.Arg.html#tymethod.as_cow_c_str" class="fn">as_cow_c_str</a>(&amp;self) -&gt; <a class="type" href="../io/type.Result.html" title="type rustix::io::Result">Result</a>&lt;<a class="enum" href="https://doc.rust-lang.org/1.84.1/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a>&lt;'_, <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>&gt;&gt;</h4></section></summary><div class='docblock'>Returns a view of this string as a maybe-owned <a href="struct.CStr.html" title="struct rustix::ffi::CStr"><code>CStr</code></a>.</div></details><details class="toggle method-toggle" open><summary><section id="method.into_c_str" class="method trait-impl"><a class="src rightside" href="../../src/rustix/path/arg.rs.html#505-510">Source</a><a href="#method.into_c_str" class="anchor">§</a><h4 class="code-header">fn <a href="../path/trait.Arg.html#tymethod.into_c_str" class="fn">into_c_str</a>&lt;'b&gt;(self) -&gt; <a class="type" href="../io/type.Result.html" title="type rustix::io::Result">Result</a>&lt;<a class="enum" href="https://doc.rust-lang.org/1.84.1/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a>&lt;'b, <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>&gt;&gt;<div class="where">where
Self: 'b,</div></h4></section></summary><div class='docblock'>Consumes <code>self</code> and returns a view of this string as a maybe-owned
<a href="struct.CStr.html" title="struct rustix::ffi::CStr"><code>CStr</code></a>.</div></details><details class="toggle method-toggle" open><summary><section id="method.into_with_c_str" class="method trait-impl"><a class="src rightside" href="../../src/rustix/path/arg.rs.html#513-519">Source</a><a href="#method.into_with_c_str" class="anchor">§</a><h4 class="code-header">fn <a href="../path/trait.Arg.html#tymethod.into_with_c_str" class="fn">into_with_c_str</a>&lt;T, F&gt;(self, f: F) -&gt; <a class="type" href="../io/type.Result.html" title="type rustix::io::Result">Result</a>&lt;T&gt;<div class="where">where
Self: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(&amp;<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>) -&gt; <a class="type" href="../io/type.Result.html" title="type rustix::io::Result">Result</a>&lt;T&gt;,</div></h4></section></summary><div class='docblock'>Runs a closure with <code>self</code> passed in as a <code>&amp;CStr</code>.</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-AsRef%3CCStr%3E-for-CStr" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.7.0">1.7.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#720">Source</a></span><a href="#impl-AsRef%3CCStr%3E-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/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="toggle method-toggle" open><summary><section id="method.as_ref" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#722">Source</a><a href="#method.as_ref" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html#tymethod.as_ref" class="fn">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'>Converts this type into a shared reference of the (usually inferred) input type.</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-AsRef%3CCStr%3E-for-CString" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.7.0">1.7.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/alloc/ffi/c_str.rs.html#1114">Source</a></span><a href="#impl-AsRef%3CCStr%3E-for-CString" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/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="toggle method-toggle" open><summary><section id="method.as_ref-1" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/alloc/ffi/c_str.rs.html#1116">Source</a><a href="#method.as_ref-1" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.AsRef.html#tymethod.as_ref" class="fn">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'>Converts this type into a shared reference of the (usually inferred) input type.</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Borrow%3CCStr%3E-for-CString" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.3.0">1.3.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/alloc/ffi/c_str.rs.html#747">Source</a></span><a href="#impl-Borrow%3CCStr%3E-for-CString" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/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="toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/alloc/ffi/c_str.rs.html#749">Source</a><a href="#method.borrow" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.Borrow.html#tymethod.borrow" class="fn">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'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-CloneToUninit-for-CStr" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/clone.rs.html#303">Source</a><a href="#impl-CloneToUninit-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/clone/trait.CloneToUninit.html" title="trait core::clone::CloneToUninit">CloneToUninit</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="toggle method-toggle" open><summary><section id="method.clone_to_uninit" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/clone.rs.html#305">Source</a><a href="#method.clone_to_uninit" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="https://doc.rust-lang.org/1.84.1/core/clone/trait.CloneToUninit.html#tymethod.clone_to_uninit" class="fn">clone_to_uninit</a>(&amp;self, dst: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.pointer.html">*mut </a><a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u8.html">u8</a>)</h4></section></summary><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span><span>This is a nightly-only experimental API. (<code>clone_to_uninit</code>)</span></div></span><div class='docblock'>Performs copy-assignment from <code>self</code> to <code>dst</code>. <a href="https://doc.rust-lang.org/1.84.1/core/clone/trait.CloneToUninit.html#tymethod.clone_to_uninit">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Debug-for-CStr" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.3.0">1.3.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#183">Source</a></span><a href="#impl-Debug-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/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="toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#184">Source</a><a href="#method.fmt" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/fmt/trait.Debug.html#tymethod.fmt" class="fn">fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="https://doc.rust-lang.org/1.84.1/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.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.unit.html">()</a>, <a class="struct" href="https://doc.rust-lang.org/1.84.1/core/fmt/struct.Error.html" title="struct core::fmt::Error">Error</a>&gt;</h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/1.84.1/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Default-for-%26CStr" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.10.0">1.10.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#190">Source</a></span><a href="#impl-Default-for-%26CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/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="toggle method-toggle" open><summary><section id="method.default" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#192">Source</a><a href="#method.default" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/default/trait.Default.html#tymethod.default" class="fn">default</a>() -&gt; &amp;<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h4></section></summary><div class='docblock'>Returns the “default value” for a type. <a href="https://doc.rust-lang.org/1.84.1/core/default/trait.Default.html#tymethod.default">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-From%3C%26CStr%3E-for-CString" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.7.0">1.7.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/alloc/ffi/c_str.rs.html#1095">Source</a></span><a href="#impl-From%3C%26CStr%3E-for-CString" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/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="toggle method-toggle" open><summary><section id="method.from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/alloc/ffi/c_str.rs.html#1098">Source</a><a href="#method.from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.From.html#tymethod.from" class="fn">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 a <code>&amp;<a href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></code> into a <a href="struct.CString.html" title="struct rustix::ffi::CString"><code>CString</code></a>
by copying the contents into a new allocation.</p>
</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Hash-for-CStr" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.64.0">1.64.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#93">Source</a></span><a href="#impl-Hash-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/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="toggle method-toggle" open><summary><section id="method.hash" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#93">Source</a><a href="#method.hash" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/hash/trait.Hash.html#tymethod.hash" class="fn">hash</a>&lt;__H&gt;(&amp;self, state: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut __H</a>)<div class="where">where
__H: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/hash/trait.Hasher.html" title="trait core::hash::Hasher">Hasher</a>,</div></h4></section></summary><div class='docblock'>Feeds this value into the given <a href="https://doc.rust-lang.org/1.84.1/core/hash/trait.Hasher.html" title="trait core::hash::Hasher"><code>Hasher</code></a>. <a href="https://doc.rust-lang.org/1.84.1/core/hash/trait.Hash.html#tymethod.hash">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Index%3CRangeFrom%3Cusize%3E%3E-for-CStr" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.47.0">1.47.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#697">Source</a></span><a href="#impl-Index%3CRangeFrom%3Cusize%3E%3E-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/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.84.1/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.84.1/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="toggle" open><summary><section id="associatedtype.Output" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#698">Source</a><a href="#associatedtype.Output" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.84.1/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'>The returned type after indexing.</div></details><details class="toggle method-toggle" open><summary><section id="method.index" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#701">Source</a><a href="#method.index" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/ops/index/trait.Index.html#tymethod.index" class="fn">index</a>(&amp;self, index: <a class="struct" href="https://doc.rust-lang.org/1.84.1/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.84.1/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'>Performs the indexing (<code>container[index]</code>) operation. <a href="https://doc.rust-lang.org/1.84.1/core/ops/index/trait.Index.html#tymethod.index">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Ord-for-CStr" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#689">Source</a></span><a href="#impl-Ord-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/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="toggle method-toggle" open><summary><section id="method.cmp" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#691">Source</a><a href="#method.cmp" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.Ord.html#tymethod.cmp" class="fn">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.84.1/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a></h4></section></summary><div class='docblock'>This method returns an <a href="https://doc.rust-lang.org/1.84.1/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering"><code>Ordering</code></a> between <code>self</code> and <code>other</code>. <a href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.Ord.html#tymethod.cmp">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-PartialEq-for-CStr" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.64.0">1.64.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#93">Source</a></span><a href="#impl-PartialEq-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</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="toggle method-toggle" open><summary><section id="method.eq" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#93">Source</a><a href="#method.eq" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.PartialEq.html#tymethod.eq" class="fn">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.84.1/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>Tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>.</div></details><details class="toggle method-toggle" open><summary><section id="method.ne" class="method trait-impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/cmp.rs.html#261">Source</a></span><a href="#method.ne" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.PartialEq.html#method.ne" class="fn">ne</a>(&amp;self, other: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;Rhs</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>Tests for <code>!=</code>. The default implementation is almost always sufficient,
and should not be overridden without very good reason.</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-PartialOrd-for-CStr" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#682">Source</a></span><a href="#impl-PartialOrd-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</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="toggle method-toggle" open><summary><section id="method.partial_cmp" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#684">Source</a><a href="#method.partial_cmp" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.PartialOrd.html#tymethod.partial_cmp" class="fn">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.84.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="https://doc.rust-lang.org/1.84.1/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>&gt;</h4></section></summary><div class='docblock'>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.84.1/core/cmp/trait.PartialOrd.html#tymethod.partial_cmp">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.lt" class="method trait-impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/cmp.rs.html#1335">Source</a></span><a href="#method.lt" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.PartialOrd.html#method.lt" class="fn">lt</a>(&amp;self, other: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;Rhs</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>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.84.1/core/cmp/trait.PartialOrd.html#method.lt">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.le" class="method trait-impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/cmp.rs.html#1353">Source</a></span><a href="#method.le" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.PartialOrd.html#method.le" class="fn">le</a>(&amp;self, other: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;Rhs</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>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.84.1/core/cmp/trait.PartialOrd.html#method.le">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.gt" class="method trait-impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/cmp.rs.html#1371">Source</a></span><a href="#method.gt" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.PartialOrd.html#method.gt" class="fn">gt</a>(&amp;self, other: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;Rhs</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>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.84.1/core/cmp/trait.PartialOrd.html#method.gt">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.ge" class="method trait-impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/cmp.rs.html#1389">Source</a></span><a href="#method.ge" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.PartialOrd.html#method.ge" class="fn">ge</a>(&amp;self, other: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;Rhs</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>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.84.1/core/cmp/trait.PartialOrd.html#method.ge">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-ToOwned-for-CStr" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.3.0">1.3.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/alloc/ffi/c_str.rs.html#1080">Source</a></span><a href="#impl-ToOwned-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/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="toggle" open><summary><section id="associatedtype.Owned" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/alloc/ffi/c_str.rs.html#1081">Source</a><a href="#associatedtype.Owned" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.84.1/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'>The resulting type after obtaining ownership.</div></details><details class="toggle method-toggle" open><summary><section id="method.to_owned" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/alloc/ffi/c_str.rs.html#1083">Source</a><a href="#method.to_owned" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/alloc/borrow/trait.ToOwned.html#tymethod.to_owned" class="fn">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'>Creates owned data from borrowed data, usually by cloning. <a href="https://doc.rust-lang.org/1.84.1/alloc/borrow/trait.ToOwned.html#tymethod.to_owned">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.clone_into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/alloc/ffi/c_str.rs.html#1087">Source</a><a href="#method.clone_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/alloc/borrow/trait.ToOwned.html#method.clone_into" class="fn">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'>Uses borrowed data to replace owned data, usually by cloning. <a href="https://doc.rust-lang.org/1.84.1/alloc/borrow/trait.ToOwned.html#method.clone_into">Read more</a></div></details></div></details><section id="impl-Eq-for-CStr" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.64.0">1.64.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#93">Source</a></span><a href="#impl-Eq-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/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><section id="impl-StructuralPartialEq-for-CStr" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.64.0">1.64.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.1/src/core/ffi/c_str.rs.html#93">Source</a></span><a href="#impl-StructuralPartialEq-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.StructuralPartialEq.html" title="trait core::marker::StructuralPartialEq">StructuralPartialEq</a> for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section></div><h2 id="synthetic-implementations" class="section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor">§</a></h2><div id="synthetic-implementations-list"><section id="impl-Freeze-for-CStr" class="impl"><a href="#impl-Freeze-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a> for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section><section id="impl-RefUnwindSafe-for-CStr" class="impl"><a href="#impl-RefUnwindSafe-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/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"><a href="#impl-Send-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/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"><a href="#impl-Sized-for-CStr" class="anchor">§</a><h3 class="code-header">impl !<a class="trait" href="https://doc.rust-lang.org/1.84.1/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"><a href="#impl-Sync-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/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"><a href="#impl-Unpin-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/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"><a href="#impl-UnwindSafe-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/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="section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor">§</a></h2><div id="blanket-implementations-list"><details class="toggle implementors-toggle"><summary><section id="impl-Any-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/any.rs.html#138">Source</a><a href="#impl-Any-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T<div class="where">where
T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/any.rs.html#139">Source</a><a href="#method.type_id" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/any/trait.Any.html#tymethod.type_id" class="fn">type_id</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.84.1/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/1.84.1/core/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/borrow.rs.html#209">Source</a><a href="#impl-Borrow%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a>&lt;T&gt; for T<div class="where">where
T: ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow-1" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/borrow.rs.html#211">Source</a><a href="#method.borrow-1" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.Borrow.html#tymethod.borrow" class="fn">borrow</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;T</a></h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/borrow.rs.html#217">Source</a><a href="#impl-BorrowMut%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a>&lt;T&gt; for T<div class="where">where
T: ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/borrow.rs.html#218">Source</a><a href="#method.borrow_mut" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fn">borrow_mut</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut T</a></h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></div></details></div></details></div><script type="text/json" id="notable-traits-data">{"&[u8]":"<h3>Notable traits for <code>&amp;[<a class=\"primitive\" href=\"https://doc.rust-lang.org/1.84.1/std/primitive.u8.html\">u8</a>]</code></h3><pre><code><div class=\"where\">impl <a class=\"trait\" href=\"https://doc.rust-lang.org/1.84.1/std/io/trait.Read.html\" title=\"trait std::io::Read\">Read</a> for &amp;[<a class=\"primitive\" href=\"https://doc.rust-lang.org/1.84.1/std/primitive.u8.html\">u8</a>]</div>"}</script></section></div></main></body></html>