Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-release > by-pkgid > 0c2243f8a1696816431e7210e991fa52 > files > 14927

rust-doc-1.35.0-1.mga7.armv7hl.rpm

<!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="API documentation for the Rust `CStr` struct in crate `std`."><meta name="keywords" content="rust, rustlang, rust-lang, CStr"><title>std::ffi::CStr - Rust</title><link rel="stylesheet" type="text/css" href="../../normalize1.35.0.css"><link rel="stylesheet" type="text/css" href="../../rustdoc1.35.0.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../dark1.35.0.css"><link rel="stylesheet" type="text/css" href="../../light1.35.0.css" id="themeStyle"><script src="../../storage1.35.0.js"></script><noscript><link rel="stylesheet" href="../../noscript1.35.0.css"></noscript><link rel="shortcut icon" href="../../favicon1.35.0.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow1.35.0.svg");}</style></head><body class="rustdoc struct"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><a href='../../std/index.html'><img src='../../rust-logo1.35.0.png' alt='logo' width='100'></a><p class='location'>Struct CStr</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.as_ptr">as_ptr</a><a href="#method.from_bytes_with_nul">from_bytes_with_nul</a><a href="#method.from_bytes_with_nul_unchecked">from_bytes_with_nul_unchecked</a><a href="#method.from_ptr">from_ptr</a><a href="#method.into_c_string">into_c_string</a><a href="#method.to_bytes">to_bytes</a><a href="#method.to_bytes_with_nul">to_bytes_with_nul</a><a href="#method.to_str">to_str</a><a href="#method.to_string_lossy">to_string_lossy</a></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-AsRef%3CCStr%3E">AsRef&lt;CStr&gt;</a><a href="#impl-Borrow%3CCStr%3E">Borrow&lt;CStr&gt;</a><a href="#impl-Debug">Debug</a><a href="#impl-Default">Default</a><a href="#impl-Eq">Eq</a><a href="#impl-From%3C%26%27_%20CStr%3E">From&lt;&amp;&#39;_ CStr&gt;</a><a href="#impl-From%3C%26%27a%20CStr%3E">From&lt;&amp;&#39;a CStr&gt;</a><a href="#impl-Hash">Hash</a><a href="#impl-Ord">Ord</a><a href="#impl-PartialEq%3CCStr%3E">PartialEq&lt;CStr&gt;</a><a href="#impl-PartialOrd%3CCStr%3E">PartialOrd&lt;CStr&gt;</a><a href="#impl-ToOwned">ToOwned</a></div><a class="sidebar-title" href="#synthetic-implementations">Auto Trait Implementations</a><div class="sidebar-links"><a href="#impl-Send">Send</a><a href="#impl-Sync">Sync</a></div><a class="sidebar-title" href="#blanket-implementations">Blanket Implementations</a><div class="sidebar-links"><a href="#impl-Any">Any</a><a href="#impl-Borrow">Borrow</a><a href="#impl-BorrowMut">BorrowMut</a><a href="#impl-ToOwned">ToOwned</a></div></div><p class='location'><a href='../index.html'>std</a>::<wbr><a href='index.html'>ffi</a></p><script>window.sidebarCurrent = {name: 'CStr', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../../brush1.35.0.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../../theme1.35.0.js"></script><nav class="sub"><form class="search-form js-only"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><a id="settings-menu" href="../../settings.html"><img src="../../wheel1.35.0.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='out-of-band'><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>&#x2212;</span>]</a></span><a class='srclink' href='../../src/std/ffi/c_str.rs.html#196-202' title='goto source code'>[src]</a></span><span class='in-band'>Struct <a href='../index.html'>std</a>::<wbr><a href='index.html'>ffi</a>::<wbr><a class="struct" href=''>CStr</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class='rust struct'>pub struct CStr { /* fields omitted */ }</pre></div><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;[</code><a href="../primitive.u8.html"><code>u8</code></a><code>]</code>
slice, or unsafely from a raw <code>*const c_char</code>. It can then be
converted to a Rust <a href="../primitive.str.html"><code>&amp;str</code></a> by performing UTF-8 validation, or
into an owned <a href="struct.CString.html"><code>CString</code></a>.</p>
<p><code>&amp;CStr</code> is to <a href="struct.CString.html"><code>CString</code></a> as <a href="../primitive.str.html"><code>&amp;str</code></a> is to <a href="../string/struct.String.html"><code>String</code></a>: 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="#method.from_ptr"><code>from_ptr</code></a> constructor to provide a safe
interface to other consumers.</p>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
<p>Inspecting a foreign C string:</p>

<div class='information'><div class='tooltip ignore'>ⓘ<span class='tooltiptext'>This example is not tested</span></div></div><div class="example-wrap"><pre class="rust rust-example-rendered ignore">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">ffi</span>::<span class="ident">CStr</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">os</span>::<span class="ident">raw</span>::<span class="ident">c_char</span>;

<span class="kw">extern</span> { <span class="kw">fn</span> <span class="ident">my_string</span>() <span class="op">-&gt;</span> <span class="kw-2">*</span><span class="kw">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</span>::<span class="ident">from_ptr</span>(<span class="ident">my_string</span>());
    <span class="macro">println</span><span class="macro">!</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>());
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Affi%3A%3ACStr%3B%0Ause%20std%3A%3Aos%3A%3Araw%3A%3Ac_char%3B%0A%0Aextern%20%7B%20fn%20my_string()%20-%3E%20*const%20c_char%3B%20%7D%0A%0Aunsafe%20%7B%0A%20%20%20%20let%20slice%20%3D%20CStr%3A%3Afrom_ptr(my_string())%3B%0A%20%20%20%20println!(%22string%20buffer%20size%20without%20nul%20terminator%3A%20%7B%7D%22%2C%20slice.to_bytes().len())%3B%0A%7D%0A%7D">Run</a></pre></div>
<p>Passing a Rust-originating C string:</p>

<div class='information'><div class='tooltip ignore'>ⓘ<span class='tooltiptext'>This example is not tested</span></div></div><div class="example-wrap"><pre class="rust rust-example-rendered ignore">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">ffi</span>::{<span class="ident">CString</span>, <span class="ident">CStr</span>};
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">os</span>::<span class="ident">raw</span>::<span class="ident">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="kw">fn</span> <span class="ident">work_with</span>(<span class="ident">data</span>: <span class="kw-2">*</span><span class="kw">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</span>::<span class="ident">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>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Affi%3A%3A%7BCString%2C%20CStr%7D%3B%0Ause%20std%3A%3Aos%3A%3Araw%3A%3Ac_char%3B%0A%0Afn%20work(data%3A%20%26CStr)%20%7B%0A%20%20%20%20extern%20%7B%20fn%20work_with(data%3A%20*const%20c_char)%3B%20%7D%0A%0A%20%20%20%20unsafe%20%7B%20work_with(data.as_ptr())%20%7D%0A%7D%0A%0Alet%20s%20%3D%20CString%3A%3Anew(%22data%20data%20data%20data%22).expect(%22CString%3A%3Anew%20failed%22)%3B%0Awork(%26s)%3B%0A%7D">Run</a></pre></div>
<p>Converting a foreign C string into a Rust <a href="../string/struct.String.html"><code>String</code></a>:</p>

<div class='information'><div class='tooltip ignore'>ⓘ<span class='tooltiptext'>This example is not tested</span></div></div><div class="example-wrap"><pre class="rust rust-example-rendered ignore">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">ffi</span>::<span class="ident">CStr</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">os</span>::<span class="ident">raw</span>::<span class="ident">c_char</span>;

<span class="kw">extern</span> { <span class="kw">fn</span> <span class="ident">my_string</span>() <span class="op">-&gt;</span> <span class="kw-2">*</span><span class="kw">const</span> <span class="ident">c_char</span>; }

<span class="kw">fn</span> <span class="ident">my_string_safe</span>() <span class="op">-&gt;</span> <span class="ident">String</span> {
    <span class="kw">unsafe</span> {
        <span class="ident">CStr</span>::<span class="ident">from_ptr</span>(<span class="ident">my_string</span>()).<span class="ident">to_string_lossy</span>().<span class="ident">into_owned</span>()
    }
}

<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;string: {}&quot;</span>, <span class="ident">my_string_safe</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Affi%3A%3ACStr%3B%0Ause%20std%3A%3Aos%3A%3Araw%3A%3Ac_char%3B%0A%0Aextern%20%7B%20fn%20my_string()%20-%3E%20*const%20c_char%3B%20%7D%0A%0Afn%20my_string_safe()%20-%3E%20String%20%7B%0A%20%20%20%20unsafe%20%7B%0A%20%20%20%20%20%20%20%20CStr%3A%3Afrom_ptr(my_string()).to_string_lossy().into_owned()%0A%20%20%20%20%7D%0A%7D%0A%0Aprintln!(%22string%3A%20%7B%7D%22%2C%20my_string_safe())%3B%0A%7D">Run</a></pre></div>
</div><h2 id='methods' class='small-section-header'>Methods<a href='#methods' class='anchor'></a></h2><h3 id='impl' class='impl'><code class='in-band'>impl <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><a href='#impl' class='anchor'></a><a class='srclink' href='../../src/std/ffi/c_str.rs.html#925-1238' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from_ptr' class="method"><code id='from_ptr.v'>pub unsafe fn <a href='#method.from_ptr' class='fnname'>from_ptr</a>&lt;'a&gt;(ptr: <a class="primitive" href="../primitive.pointer.html">*const </a><a class="type" href="../../std/os/raw/type.c_char.html" title="type std::os::raw::c_char">c_char</a>) -&gt; &amp;'a <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><a class='srclink' href='../../src/std/ffi/c_str.rs.html#962-966' title='goto source code'>[src]</a></h4><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. This method
is unsafe for a number of reasons:</p>
<ul>
<li>There is no guarantee to the validity of <code>ptr</code>.</li>
<li>The returned lifetime is not guaranteed to be the actual lifetime of
<code>ptr</code>.</li>
<li>There is no guarantee that the memory pointed to by <code>ptr</code> contains a
valid nul terminator byte at the end of the string.</li>
<li>It is not guaranteed that the memory pointed by <code>ptr</code> won't change
before the <code>CStr</code> has been destroyed.</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>
<h1 id="examples-1" class="section-header"><a href="#examples-1">Examples</a></h1>
<div class='information'><div class='tooltip ignore'>ⓘ<span class='tooltiptext'>This example is not tested</span></div></div><div class="example-wrap"><pre class="rust rust-example-rendered ignore">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">ffi</span>::<span class="ident">CStr</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">os</span>::<span class="ident">raw</span>::<span class="ident">c_char</span>;

<span class="kw">extern</span> {
    <span class="kw">fn</span> <span class="ident">my_string</span>() <span class="op">-&gt;</span> <span class="kw-2">*</span><span class="kw">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</span>::<span class="ident">from_ptr</span>(<span class="ident">my_string</span>());
    <span class="macro">println</span><span class="macro">!</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>());
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Affi%3A%3ACStr%3B%0Ause%20std%3A%3Aos%3A%3Araw%3A%3Ac_char%3B%0A%0Aextern%20%7B%0A%20%20%20%20fn%20my_string()%20-%3E%20*const%20c_char%3B%0A%7D%0A%0Aunsafe%20%7B%0A%20%20%20%20let%20slice%20%3D%20CStr%3A%3Afrom_ptr(my_string())%3B%0A%20%20%20%20println!(%22string%20returned%3A%20%7B%7D%22%2C%20slice.to_str().unwrap())%3B%0A%7D%0A%7D">Run</a></pre></div>
</div><h4 id='method.from_bytes_with_nul' class="method"><code id='from_bytes_with_nul.v'>pub fn <a href='#method.from_bytes_with_nul' class='fnname'>from_bytes_with_nul</a>(bytes: <a class="primitive" href="../primitive.slice.html">&amp;[</a><a class="primitive" href="../primitive.u8.html">u8</a><a class="primitive" href="../primitive.slice.html">]</a>) -&gt; <a class="enum" href="../../std/result/enum.Result.html" title="enum std::result::Result">Result</a>&lt;&amp;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>, <a class="struct" href="../../std/ffi/struct.FromBytesWithNulError.html" title="struct std::ffi::FromBytesWithNulError">FromBytesWithNulError</a>&gt;</code><div class='since' title='Stable since Rust version 1.10.0'>1.10.0</div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1001-1012' title='goto source code'>[src]</a></h4><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>
<h1 id="examples-2" class="section-header"><a href="#examples-2">Examples</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">ffi</span>::<span class="ident">CStr</span>;

<span class="kw">let</span> <span class="ident">cstr</span> <span class="op">=</span> <span class="ident">CStr</span>::<span class="ident">from_bytes_with_nul</span>(<span class="string">b&quot;hello\0&quot;</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">cstr</span>.<span class="ident">is_ok</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Affi%3A%3ACStr%3B%0A%0Alet%20cstr%20%3D%20CStr%3A%3Afrom_bytes_with_nul(b%22hello%5C0%22)%3B%0Aassert!(cstr.is_ok())%3B%0A%7D">Run</a></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">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">ffi</span>::<span class="ident">CStr</span>;

<span class="kw">let</span> <span class="ident">c_str</span> <span class="op">=</span> <span class="ident">CStr</span>::<span class="ident">from_bytes_with_nul</span>(<span class="string">b&quot;hello&quot;</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">c_str</span>.<span class="ident">is_err</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Affi%3A%3ACStr%3B%0A%0Alet%20c_str%20%3D%20CStr%3A%3Afrom_bytes_with_nul(b%22hello%22)%3B%0Aassert!(c_str.is_err())%3B%0A%7D">Run</a></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">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">ffi</span>::<span class="ident">CStr</span>;

<span class="kw">let</span> <span class="ident">c_str</span> <span class="op">=</span> <span class="ident">CStr</span>::<span class="ident">from_bytes_with_nul</span>(<span class="string">b&quot;he\0llo\0&quot;</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">c_str</span>.<span class="ident">is_err</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Affi%3A%3ACStr%3B%0A%0Alet%20c_str%20%3D%20CStr%3A%3Afrom_bytes_with_nul(b%22he%5C0llo%5C0%22)%3B%0Aassert!(c_str.is_err())%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.from_bytes_with_nul_unchecked' class="method"><code id='from_bytes_with_nul_unchecked.v'>pub const unsafe fn <a href='#method.from_bytes_with_nul_unchecked' class='fnname'>from_bytes_with_nul_unchecked</a>(bytes: <a class="primitive" href="../primitive.slice.html">&amp;[</a><a class="primitive" href="../primitive.u8.html">u8</a><a class="primitive" href="../primitive.slice.html">]</a>) -&gt; &amp;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><div class='since' title='Stable since Rust version 1.10.0'>1.10.0</div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1034-1036' title='goto source code'>[src]</a></h4><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. The provided slice <strong>must</strong> be nul-terminated
and not contain any interior nul bytes.</p>
<h1 id="examples-3" class="section-header"><a href="#examples-3">Examples</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">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</span>::<span class="ident">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</span>::<span class="ident">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="macro">!</span>(<span class="ident">cstr</span>, <span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">cstring</span>);
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Affi%3A%3A%7BCStr%2C%20CString%7D%3B%0A%0Aunsafe%20%7B%0A%20%20%20%20let%20cstring%20%3D%20CString%3A%3Anew(%22hello%22).expect(%22CString%3A%3Anew%20failed%22)%3B%0A%20%20%20%20let%20cstr%20%3D%20CStr%3A%3Afrom_bytes_with_nul_unchecked(cstring.to_bytes_with_nul())%3B%0A%20%20%20%20assert_eq!(cstr%2C%20%26*cstring)%3B%0A%7D%0A%7D">Run</a></pre></div>
</div><h4 id='method.as_ptr' class="method"><code id='as_ptr.v'>pub const fn <a href='#method.as_ptr' class='fnname'>as_ptr</a>(&amp;self) -&gt; <a class="primitive" href="../primitive.pointer.html">*const </a><a class="type" href="../../std/os/raw/type.c_char.html" title="type std::os::raw::c_char">c_char</a></code><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1084-1086' title='goto source code'>[src]</a></h4><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>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">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">ffi</span>::{<span class="ident">CString</span>};

<span class="kw">let</span> <span class="ident">ptr</span> <span class="op">=</span> <span class="ident">CString</span>::<span class="ident">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>;
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0A%23!%5Ballow(unused_must_use)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Affi%3A%3A%7BCString%7D%3B%0A%0Alet%20ptr%20%3D%20CString%3A%3Anew(%22Hello%22).expect(%22CString%3A%3Anew%20failed%22).as_ptr()%3B%0Aunsafe%20%7B%0A%20%20%20%20%2F%2F%20%60ptr%60%20is%20dangling%0A%20%20%20%20*ptr%3B%0A%7D%0A%7D">Run</a></pre></div>
<p>This happens because the pointer returned by <code>as_ptr</code> does not carry any
lifetime information and the <a href="struct.CString.html"><code>CString</code></a> 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">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">ffi</span>::{<span class="ident">CString</span>};

<span class="kw">let</span> <span class="ident">hello</span> <span class="op">=</span> <span class="ident">CString</span>::<span class="ident">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>;
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0A%23!%5Ballow(unused_must_use)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Affi%3A%3A%7BCString%7D%3B%0A%0Alet%20hello%20%3D%20CString%3A%3Anew(%22Hello%22).expect(%22CString%3A%3Anew%20failed%22)%3B%0Alet%20ptr%20%3D%20hello.as_ptr()%3B%0Aunsafe%20%7B%0A%20%20%20%20%2F%2F%20%60ptr%60%20is%20valid%20because%20%60hello%60%20is%20in%20scope%0A%20%20%20%20*ptr%3B%0A%7D%0A%7D">Run</a></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><h4 id='method.to_bytes' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="primitive" href="../primitive.slice.html">&amp;'_ [</a><a class="primitive" href="../primitive.u8.html">u8</a><a class="primitive" href="../primitive.slice.html">]</a></span></div><div class="content hidden"><h3 class="important">Important traits for <a class="primitive" href="../primitive.slice.html">&amp;'_ [</a><a class="primitive" href="../primitive.u8.html">u8</a><a class="primitive" href="../primitive.slice.html">]</a></h3><code class="content"><span class="where fmt-newline">impl&lt;'_&gt; <a class="trait" href="../../std/io/trait.Read.html" title="trait std::io::Read">Read</a> for <a class="primitive" href="../primitive.slice.html">&amp;'_ [</a><a class="primitive" href="../primitive.u8.html">u8</a><a class="primitive" href="../primitive.slice.html">]</a></span><span class="where fmt-newline">impl&lt;'_&gt; <a class="trait" href="../../std/io/trait.Write.html" title="trait std::io::Write">Write</a> for <a class="primitive" href="../primitive.slice.html">&amp;'_ mut [</a><a class="primitive" href="../primitive.u8.html">u8</a><a class="primitive" href="../primitive.slice.html">]</a></span></code></div></div><code id='to_bytes.v'>pub fn <a href='#method.to_bytes' class='fnname'>to_bytes</a>(&amp;self) -&gt; <a class="primitive" href="../primitive.slice.html">&amp;[</a><a class="primitive" href="../primitive.u8.html">u8</a><a class="primitive" href="../primitive.slice.html">]</a></code><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1107-1110' title='goto source code'>[src]</a></h4><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>
<h1 id="examples-4" class="section-header"><a href="#examples-4">Examples</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">ffi</span>::<span class="ident">CStr</span>;

<span class="kw">let</span> <span class="ident">c_str</span> <span class="op">=</span> <span class="ident">CStr</span>::<span class="ident">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="macro">!</span>(<span class="ident">c_str</span>.<span class="ident">to_bytes</span>(), <span class="string">b&quot;foo&quot;</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Affi%3A%3ACStr%3B%0A%0Alet%20c_str%20%3D%20CStr%3A%3Afrom_bytes_with_nul(b%22foo%5C0%22).expect(%22CStr%3A%3Afrom_bytes_with_nul%20failed%22)%3B%0Aassert_eq!(c_str.to_bytes()%2C%20b%22foo%22)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.to_bytes_with_nul' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="primitive" href="../primitive.slice.html">&amp;'_ [</a><a class="primitive" href="../primitive.u8.html">u8</a><a class="primitive" href="../primitive.slice.html">]</a></span></div><div class="content hidden"><h3 class="important">Important traits for <a class="primitive" href="../primitive.slice.html">&amp;'_ [</a><a class="primitive" href="../primitive.u8.html">u8</a><a class="primitive" href="../primitive.slice.html">]</a></h3><code class="content"><span class="where fmt-newline">impl&lt;'_&gt; <a class="trait" href="../../std/io/trait.Read.html" title="trait std::io::Read">Read</a> for <a class="primitive" href="../primitive.slice.html">&amp;'_ [</a><a class="primitive" href="../primitive.u8.html">u8</a><a class="primitive" href="../primitive.slice.html">]</a></span><span class="where fmt-newline">impl&lt;'_&gt; <a class="trait" href="../../std/io/trait.Write.html" title="trait std::io::Write">Write</a> for <a class="primitive" href="../primitive.slice.html">&amp;'_ mut [</a><a class="primitive" href="../primitive.u8.html">u8</a><a class="primitive" href="../primitive.slice.html">]</a></span></code></div></div><code id='to_bytes_with_nul.v'>pub fn <a href='#method.to_bytes_with_nul' class='fnname'>to_bytes_with_nul</a>(&amp;self) -&gt; <a class="primitive" href="../primitive.slice.html">&amp;[</a><a class="primitive" href="../primitive.u8.html">u8</a><a class="primitive" href="../primitive.slice.html">]</a></code><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1133-1135' title='goto source code'>[src]</a></h4><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="#method.to_bytes"><code>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>
<h1 id="examples-5" class="section-header"><a href="#examples-5">Examples</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">ffi</span>::<span class="ident">CStr</span>;

<span class="kw">let</span> <span class="ident">c_str</span> <span class="op">=</span> <span class="ident">CStr</span>::<span class="ident">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="macro">!</span>(<span class="ident">c_str</span>.<span class="ident">to_bytes_with_nul</span>(), <span class="string">b&quot;foo\0&quot;</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Affi%3A%3ACStr%3B%0A%0Alet%20c_str%20%3D%20CStr%3A%3Afrom_bytes_with_nul(b%22foo%5C0%22).expect(%22CStr%3A%3Afrom_bytes_with_nul%20failed%22)%3B%0Aassert_eq!(c_str.to_bytes_with_nul()%2C%20b%22foo%5C0%22)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.to_str' class="method"><code id='to_str.v'>pub fn <a href='#method.to_str' class='fnname'>to_str</a>(&amp;self) -&gt; <a class="enum" href="../../std/result/enum.Result.html" title="enum std::result::Result">Result</a>&lt;&amp;<a class="primitive" href="../primitive.str.html">str</a>, <a class="struct" href="../../std/str/struct.Utf8Error.html" title="struct std::str::Utf8Error">Utf8Error</a>&gt;</code><div class='since' title='Stable since Rust version 1.4.0'>1.4.0</div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1159-1165' title='goto source code'>[src]</a></h4><div class='docblock'><p>Yields a <a href="../primitive.str.html"><code>&amp;str</code></a> 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 <a href="../primitive.str.html"><code>&amp;str</code></a> slice. Otherwise,
it will return an error with details of where UTF-8 validation failed.</p>
<blockquote>
<p><strong>Note</strong>: This method is currently implemented to check for validity
after a constant-time cast, but it is planned to alter its definition
in the future to perform the length calculation in addition to the
UTF-8 check whenever this method is called.</p>
</blockquote>
<h1 id="examples-6" class="section-header"><a href="#examples-6">Examples</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">ffi</span>::<span class="ident">CStr</span>;

<span class="kw">let</span> <span class="ident">c_str</span> <span class="op">=</span> <span class="ident">CStr</span>::<span class="ident">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="macro">!</span>(<span class="ident">c_str</span>.<span class="ident">to_str</span>(), <span class="prelude-val">Ok</span>(<span class="string">&quot;foo&quot;</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Affi%3A%3ACStr%3B%0A%0Alet%20c_str%20%3D%20CStr%3A%3Afrom_bytes_with_nul(b%22foo%5C0%22).expect(%22CStr%3A%3Afrom_bytes_with_nul%20failed%22)%3B%0Aassert_eq!(c_str.to_str()%2C%20Ok(%22foo%22))%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.to_string_lossy' class="method"><code id='to_string_lossy.v'>pub fn <a href='#method.to_string_lossy' class='fnname'>to_string_lossy</a>(&amp;self) -&gt; <a class="enum" href="../../std/borrow/enum.Cow.html" title="enum std::borrow::Cow">Cow</a>&lt;<a class="primitive" href="../primitive.str.html">str</a>&gt;</code><div class='since' title='Stable since Rust version 1.4.0'>1.4.0</div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1215-1217' title='goto source code'>[src]</a></h4><div class='docblock'><p>Converts a <code>CStr</code> into a <a href="../borrow/enum.Cow.html"><code>Cow</code></a><code>&lt;</code><a href="../primitive.str.html"><code>str</code></a><code>&gt;</code>.</p>
<p>If the contents of the <code>CStr</code> are valid UTF-8 data, this
function will return a <a href="../borrow/enum.Cow.html"><code>Cow</code></a><code>::</code><a href="../borrow/enum.Cow.html#variant.Borrowed"><code>Borrowed</code></a><code>(</code>[<code>&amp;str</code>]<code>)</code>
with the corresponding [<code>&amp;str</code>] slice. Otherwise, it will
replace any invalid UTF-8 sequences with
<a href="../char/constant.REPLACEMENT_CHARACTER.html"><code>U+FFFD REPLACEMENT CHARACTER</code></a> and return a
<a href="../borrow/enum.Cow.html"><code>Cow</code></a><code>::</code><a href="../borrow/enum.Cow.html#variant.Owned"><code>Owned</code></a><code>(</code><a href="../string/struct.String.html"><code>String</code></a><code>)</code> with the result.</p>
<blockquote>
<p><strong>Note</strong>: This method is currently implemented to check for validity
after a constant-time cast, but it is planned to alter its definition
in the future to perform the length calculation in addition to the
UTF-8 check whenever this method is called.</p>
</blockquote>
<h1 id="examples-7" class="section-header"><a href="#examples-7">Examples</a></h1>
<p>Calling <code>to_string_lossy</code> on a <code>CStr</code> containing valid UTF-8:</p>

<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">borrow</span>::<span class="ident">Cow</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">ffi</span>::<span class="ident">CStr</span>;

<span class="kw">let</span> <span class="ident">c_str</span> <span class="op">=</span> <span class="ident">CStr</span>::<span class="ident">from_bytes_with_nul</span>(<span class="string">b&quot;Hello World\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="macro">!</span>(<span class="ident">c_str</span>.<span class="ident">to_string_lossy</span>(), <span class="ident">Cow</span>::<span class="ident">Borrowed</span>(<span class="string">&quot;Hello World&quot;</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Aborrow%3A%3ACow%3B%0Ause%20std%3A%3Affi%3A%3ACStr%3B%0A%0Alet%20c_str%20%3D%20CStr%3A%3Afrom_bytes_with_nul(b%22Hello%20World%5C0%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.expect(%22CStr%3A%3Afrom_bytes_with_nul%20failed%22)%3B%0Aassert_eq!(c_str.to_string_lossy()%2C%20Cow%3A%3ABorrowed(%22Hello%20World%22))%3B%0A%7D">Run</a></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">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">borrow</span>::<span class="ident">Cow</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">ffi</span>::<span class="ident">CStr</span>;

<span class="kw">let</span> <span class="ident">c_str</span> <span class="op">=</span> <span class="ident">CStr</span>::<span class="ident">from_bytes_with_nul</span>(<span class="string">b&quot;Hello \xF0\x90\x80World\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="macro">!</span>(
    <span class="ident">c_str</span>.<span class="ident">to_string_lossy</span>(),
    <span class="ident">Cow</span>::<span class="ident">Owned</span>(<span class="ident">String</span>::<span class="ident">from</span>(<span class="string">&quot;Hello �World&quot;</span>)) <span class="kw">as</span> <span class="ident">Cow</span><span class="op">&lt;</span><span class="lifetime">&#39;_</span>, <span class="ident">str</span><span class="op">&gt;</span>
);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Aborrow%3A%3ACow%3B%0Ause%20std%3A%3Affi%3A%3ACStr%3B%0A%0Alet%20c_str%20%3D%20CStr%3A%3Afrom_bytes_with_nul(b%22Hello%20%5CxF0%5Cx90%5Cx80World%5C0%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.expect(%22CStr%3A%3Afrom_bytes_with_nul%20failed%22)%3B%0Aassert_eq!(%0A%20%20%20%20c_str.to_string_lossy()%2C%0A%20%20%20%20Cow%3A%3AOwned(String%3A%3Afrom(%22Hello%20%EF%BF%BDWorld%22))%20as%20Cow%3C'_%2C%20str%3E%0A)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.into_c_string' class="method"><code id='into_c_string.v'>pub fn <a href='#method.into_c_string' class='fnname'>into_c_string</a>(self: <a class="struct" href="../../std/boxed/struct.Box.html" title="struct std::boxed::Box">Box</a>&lt;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>&gt;) -&gt; <a class="struct" href="../../std/ffi/struct.CString.html" title="struct std::ffi::CString">CString</a></code><div class='since' title='Stable since Rust version 1.20.0'>1.20.0</div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1234-1237' title='goto source code'>[src]</a></h4><div class='docblock'><p>Converts a <a href="../boxed/struct.Box.html"><code>Box</code></a><code>&lt;CStr&gt;</code> into a <a href="struct.CString.html"><code>CString</code></a> without copying or allocating.</p>
<h1 id="examples-8" class="section-header"><a href="#examples-8">Examples</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">ffi</span>::<span class="ident">CString</span>;

<span class="kw">let</span> <span class="ident">c_string</span> <span class="op">=</span> <span class="ident">CString</span>::<span class="ident">new</span>(<span class="string">b&quot;foo&quot;</span>.<span class="ident">to_vec</span>()).<span class="ident">expect</span>(<span class="string">&quot;CString::new failed&quot;</span>);
<span class="kw">let</span> <span class="ident">boxed</span> <span class="op">=</span> <span class="ident">c_string</span>.<span class="ident">into_boxed_c_str</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">boxed</span>.<span class="ident">into_c_string</span>(), <span class="ident">CString</span>::<span class="ident">new</span>(<span class="string">&quot;foo&quot;</span>).<span class="ident">expect</span>(<span class="string">&quot;CString::new failed&quot;</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Affi%3A%3ACString%3B%0A%0Alet%20c_string%20%3D%20CString%3A%3Anew(b%22foo%22.to_vec()).expect(%22CString%3A%3Anew%20failed%22)%3B%0Alet%20boxed%20%3D%20c_string.into_boxed_c_str()%3B%0Aassert_eq!(boxed.into_c_string()%2C%20CString%3A%3Anew(%22foo%22).expect(%22CString%3A%3Anew%20failed%22))%3B%0A%7D">Run</a></pre></div>
</div></div><h2 id='implementations' class='small-section-header'>Trait Implementations<a href='#implementations' class='anchor'></a></h2><div id='implementations-list'><h3 id='impl-Debug' class='impl'><code class='in-band'>impl <a class="trait" href="../../std/fmt/trait.Debug.html" title="trait std::fmt::Debug">Debug</a> for <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><a href='#impl-Debug' class='anchor'></a><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#651-659' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.fmt' class="method hidden"><code id='fmt.v'>fn <a href='../../std/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="../../std/fmt/struct.Formatter.html" title="struct std::fmt::Formatter">Formatter</a>) -&gt; <a class="type" href="../../std/fmt/type.Result.html" title="type std::fmt::Result">Result</a></code><a class='srclink' href='../../src/std/ffi/c_str.rs.html#652-658' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Formats the value using the given formatter. <a href="../../std/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
</div></div><h3 id='impl-PartialEq%3CCStr%3E' class='impl'><code class='in-band'>impl <a class="trait" href="../../std/cmp/trait.PartialEq.html" title="trait std::cmp::PartialEq">PartialEq</a>&lt;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>&gt; for <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><a href='#impl-PartialEq%3CCStr%3E' class='anchor'></a><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1241-1245' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.eq' class="method hidden"><code id='eq.v'>fn <a href='../../std/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&amp;self, other: &amp;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>) -&gt; <a class="primitive" href="../primitive.bool.html">bool</a></code><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1242-1244' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../../std/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p>
</div><h4 id='method.ne' class="method"><code id='ne.v'><div class="docblock attributes">#[must_use]
</div>fn <a href='../../std/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&amp;self, other: <a class="primitive" href="../primitive.reference.html">&amp;</a>Rhs) -&gt; <a class="primitive" href="../primitive.bool.html">bool</a></code><a class='srclink' href='../../src/core/cmp.rs.html#200' title='goto source code'>[src]</a></h4><div class='docblock'><p>This method tests for <code>!=</code>.</p>
</div></div><h3 id='impl-Eq' class='impl'><code class='in-band'>impl <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a> for <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><a href='#impl-Eq' class='anchor'></a><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1247' title='goto source code'>[src]</a></h3><div class='impl-items'></div><h3 id='impl-Ord' class='impl'><code class='in-band'>impl <a class="trait" href="../../std/cmp/trait.Ord.html" title="trait std::cmp::Ord">Ord</a> for <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><a href='#impl-Ord' class='anchor'></a><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1255-1259' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.cmp' class="method hidden"><code id='cmp.v'>fn <a href='../../std/cmp/trait.Ord.html#tymethod.cmp' class='fnname'>cmp</a>(&amp;self, other: &amp;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>) -&gt; <a class="enum" href="../../std/cmp/enum.Ordering.html" title="enum std::cmp::Ordering">Ordering</a></code><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1256-1258' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method returns an <code>Ordering</code> between <code>self</code> and <code>other</code>. <a href="../../std/cmp/trait.Ord.html#tymethod.cmp">Read more</a></p>
</div><h4 id='method.max' class="method"><code id='max.v'>fn <a href='../../std/cmp/trait.Ord.html#method.max' class='fnname'>max</a>(self, other: Self) -&gt; Self</code><div class='since' title='Stable since Rust version 1.21.0'>1.21.0</div><a class='srclink' href='../../src/core/cmp.rs.html#549-552' title='goto source code'>[src]</a></h4><div class='docblock'><p>Compares and returns the maximum of two values. <a href="../../std/cmp/trait.Ord.html#method.max">Read more</a></p>
</div><h4 id='method.min' class="method"><code id='min.v'>fn <a href='../../std/cmp/trait.Ord.html#method.min' class='fnname'>min</a>(self, other: Self) -&gt; Self</code><div class='since' title='Stable since Rust version 1.21.0'>1.21.0</div><a class='srclink' href='../../src/core/cmp.rs.html#566-569' title='goto source code'>[src]</a></h4><div class='docblock'><p>Compares and returns the minimum of two values. <a href="../../std/cmp/trait.Ord.html#method.min">Read more</a></p>
</div><h4 id='method.clamp' class="method"><code id='clamp.v'>fn <a href='../../std/cmp/trait.Ord.html#method.clamp' class='fnname'>clamp</a>(self, min: Self, max: Self) -&gt; Self</code><a class='srclink' href='../../src/core/cmp.rs.html#590-600' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>clamp</code>&nbsp;<a href="https://github.com/rust-lang/rust/issues/44095">#44095</a>)</div></div><div class='docblock'><p>Restrict a value to a certain interval. <a href="../../std/cmp/trait.Ord.html#method.clamp">Read more</a></p>
</div></div><h3 id='impl-PartialOrd%3CCStr%3E' class='impl'><code class='in-band'>impl <a class="trait" href="../../std/cmp/trait.PartialOrd.html" title="trait std::cmp::PartialOrd">PartialOrd</a>&lt;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>&gt; for <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><a href='#impl-PartialOrd%3CCStr%3E' class='anchor'></a><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1249-1253' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.partial_cmp' class="method hidden"><code id='partial_cmp.v'>fn <a href='../../std/cmp/trait.PartialOrd.html#tymethod.partial_cmp' class='fnname'>partial_cmp</a>(&amp;self, other: &amp;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>) -&gt; <a class="enum" href="../../std/option/enum.Option.html" title="enum std::option::Option">Option</a>&lt;<a class="enum" href="../../std/cmp/enum.Ordering.html" title="enum std::cmp::Ordering">Ordering</a>&gt;</code><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1250-1252' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method returns an ordering between <code>self</code> and <code>other</code> values if one exists. <a href="../../std/cmp/trait.PartialOrd.html#tymethod.partial_cmp">Read more</a></p>
</div><h4 id='method.lt' class="method"><code id='lt.v'><div class="docblock attributes">#[must_use]
</div>fn <a href='../../std/cmp/trait.PartialOrd.html#method.lt' class='fnname'>lt</a>(&amp;self, other: <a class="primitive" href="../primitive.reference.html">&amp;</a>Rhs) -&gt; <a class="primitive" href="../primitive.bool.html">bool</a></code><a class='srclink' href='../../src/core/cmp.rs.html#772-777' title='goto source code'>[src]</a></h4><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="../../std/cmp/trait.PartialOrd.html#method.lt">Read more</a></p>
</div><h4 id='method.le' class="method"><code id='le.v'><div class="docblock attributes">#[must_use]
</div>fn <a href='../../std/cmp/trait.PartialOrd.html#method.le' class='fnname'>le</a>(&amp;self, other: <a class="primitive" href="../primitive.reference.html">&amp;</a>Rhs) -&gt; <a class="primitive" href="../primitive.bool.html">bool</a></code><a class='srclink' href='../../src/core/cmp.rs.html#794-799' title='goto source code'>[src]</a></h4><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="../../std/cmp/trait.PartialOrd.html#method.le">Read more</a></p>
</div><h4 id='method.gt' class="method"><code id='gt.v'><div class="docblock attributes">#[must_use]
</div>fn <a href='../../std/cmp/trait.PartialOrd.html#method.gt' class='fnname'>gt</a>(&amp;self, other: <a class="primitive" href="../primitive.reference.html">&amp;</a>Rhs) -&gt; <a class="primitive" href="../primitive.bool.html">bool</a></code><a class='srclink' href='../../src/core/cmp.rs.html#815-820' title='goto source code'>[src]</a></h4><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="../../std/cmp/trait.PartialOrd.html#method.gt">Read more</a></p>
</div><h4 id='method.ge' class="method"><code id='ge.v'><div class="docblock attributes">#[must_use]
</div>fn <a href='../../std/cmp/trait.PartialOrd.html#method.ge' class='fnname'>ge</a>(&amp;self, other: <a class="primitive" href="../primitive.reference.html">&amp;</a>Rhs) -&gt; <a class="primitive" href="../primitive.bool.html">bool</a></code><a class='srclink' href='../../src/core/cmp.rs.html#837-842' title='goto source code'>[src]</a></h4><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="../../std/cmp/trait.PartialOrd.html#method.ge">Read more</a></p>
</div></div><h3 id='impl-From%3C%26%27_%20CStr%3E' class='impl'><code class='in-band'>impl&lt;'_&gt; <a class="trait" href="../../std/convert/trait.From.html" title="trait std::convert::From">From</a>&lt;&amp;'_ <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>&gt; for <a class="struct" href="../../std/boxed/struct.Box.html" title="struct std::boxed::Box">Box</a>&lt;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>&gt;</code><a href='#impl-From%3C%26%27_%20CStr%3E' class='anchor'></a><div class='since' title='Stable since Rust version 1.17.0'>1.17.0</div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#693-698' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from' class="method hidden"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../std/boxed/struct.Box.html" title="struct std::boxed::Box">Box</a>&lt;I&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../std/boxed/struct.Box.html" title="struct std::boxed::Box">Box</a>&lt;I&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;I&gt; <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> for <a class="struct" href="../../std/boxed/struct.Box.html" title="struct std::boxed::Box">Box</a>&lt;I&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,&nbsp;</span></span><span class="where fmt-newline">    type <a href='../../std/iter/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = &lt;I as <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a>&gt;::<a class="type" href="../../std/iter/trait.Iterator.html#associatedtype.Item" title="type std::iter::Iterator::Item">Item</a>;</span><span class="where fmt-newline">impl&lt;F&gt; <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a> for <a class="struct" href="../../std/boxed/struct.Box.html" title="struct std::boxed::Box">Box</a>&lt;F&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="../../std/marker/trait.Unpin.html" title="trait std::marker::Unpin">Unpin</a> + <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,&nbsp;</span></span><span class="where fmt-newline">    type <a href='../../std/future/trait.Future.html#associatedtype.Output' class="type">Output</a> = &lt;F as <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a>&gt;::<a class="type" href="../../std/future/trait.Future.html#associatedtype.Output" title="type std::future::Future::Output">Output</a>;</span><span class="where fmt-newline">impl&lt;R:&nbsp;<a class="trait" href="../../std/io/trait.Read.html" title="trait std::io::Read">Read</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>&gt; <a class="trait" href="../../std/io/trait.Read.html" title="trait std::io::Read">Read</a> for <a class="struct" href="../../std/boxed/struct.Box.html" title="struct std::boxed::Box">Box</a>&lt;R&gt;</span><span class="where fmt-newline">impl&lt;W:&nbsp;<a class="trait" href="../../std/io/trait.Write.html" title="trait std::io::Write">Write</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>&gt; <a class="trait" href="../../std/io/trait.Write.html" title="trait std::io::Write">Write</a> for <a class="struct" href="../../std/boxed/struct.Box.html" title="struct std::boxed::Box">Box</a>&lt;W&gt;</span></code></div></div><code id='from.v'>fn <a href='../../std/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(s: &amp;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>) -&gt; <a class="struct" href="../../std/boxed/struct.Box.html" title="struct std::boxed::Box">Box</a>&lt;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>&gt;</code><a class='srclink' href='../../src/std/ffi/c_str.rs.html#694-697' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
</div></div><h3 id='impl-From%3C%26%27a%20CStr%3E' class='impl'><code class='in-band'>impl&lt;'a&gt; <a class="trait" href="../../std/convert/trait.From.html" title="trait std::convert::From">From</a>&lt;&amp;'a <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>&gt; for <a class="enum" href="../../std/borrow/enum.Cow.html" title="enum std::borrow::Cow">Cow</a>&lt;'a, <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>&gt;</code><a href='#impl-From%3C%26%27a%20CStr%3E' class='anchor'></a><div class='since' title='Stable since Rust version 1.28.0'>1.28.0</div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#741-746' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-1' class="method hidden"><code id='from.v-1'>fn <a href='../../std/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(s: &amp;'a <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>) -&gt; <a class="enum" href="../../std/borrow/enum.Cow.html" title="enum std::borrow::Cow">Cow</a>&lt;'a, <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>&gt;</code><a class='srclink' href='../../src/std/ffi/c_str.rs.html#743-745' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
</div></div><h3 id='impl-From%3C%26%27_%20CStr%3E-1' class='impl'><code class='in-band'>impl&lt;'_&gt; <a class="trait" href="../../std/convert/trait.From.html" title="trait std::convert::From">From</a>&lt;&amp;'_ <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>&gt; for <a class="struct" href="../../std/sync/struct.Arc.html" title="struct std::sync::Arc">Arc</a>&lt;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>&gt;</code><a href='#impl-From%3C%26%27_%20CStr%3E-1' class='anchor'></a><div class='since' title='Stable since Rust version 1.24.0'>1.24.0</div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#770-776' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-2' class="method hidden"><code id='from.v-2'>fn <a href='../../std/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(s: &amp;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>) -&gt; <a class="struct" href="../../std/sync/struct.Arc.html" title="struct std::sync::Arc">Arc</a>&lt;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>&gt;</code><a class='srclink' href='../../src/std/ffi/c_str.rs.html#772-775' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
</div></div><h3 id='impl-From%3C%26%27_%20CStr%3E-2' class='impl'><code class='in-band'>impl&lt;'_&gt; <a class="trait" href="../../std/convert/trait.From.html" title="trait std::convert::From">From</a>&lt;&amp;'_ <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>&gt; for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a>&lt;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>&gt;</code><a href='#impl-From%3C%26%27_%20CStr%3E-2' class='anchor'></a><div class='since' title='Stable since Rust version 1.24.0'>1.24.0</div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#792-798' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-3' class="method hidden"><code id='from.v-3'>fn <a href='../../std/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(s: &amp;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>) -&gt; <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a>&lt;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>&gt;</code><a class='srclink' href='../../src/std/ffi/c_str.rs.html#794-797' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
</div></div><h3 id='impl-From%3C%26%27_%20CStr%3E-3' class='impl'><code class='in-band'>impl&lt;'_&gt; <a class="trait" href="../../std/convert/trait.From.html" title="trait std::convert::From">From</a>&lt;&amp;'_ <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>&gt; for <a class="struct" href="../../std/ffi/struct.CString.html" title="struct std::ffi::CString">CString</a></code><a href='#impl-From%3C%26%27_%20CStr%3E-3' class='anchor'></a><div class='since' title='Stable since Rust version 1.7.0'>1.7.0</div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1271-1275' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-4' class="method hidden"><code id='from.v-4'>fn <a href='../../std/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(s: &amp;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>) -&gt; <a class="struct" href="../../std/ffi/struct.CString.html" title="struct std::ffi::CString">CString</a></code><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1272-1274' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
</div></div><h3 id='impl-Hash' class='impl'><code class='in-band'>impl <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a> for <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><a href='#impl-Hash' class='anchor'></a><a class='srclink' href='../../src/std/ffi/c_str.rs.html#194' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.hash' class="method hidden"><code id='hash.v'>fn <a href='../../std/hash/trait.Hash.html#tymethod.hash' class='fnname'>hash</a>&lt;__H:&nbsp;<a class="trait" href="../../std/hash/trait.Hasher.html" title="trait std::hash::Hasher">Hasher</a>&gt;(&amp;self, state: <a class="primitive" href="../primitive.reference.html">&amp;mut </a>__H)</code><a class='srclink' href='../../src/std/ffi/c_str.rs.html#194' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Feeds this value into the given [<code>Hasher</code>]. <a href="../../std/hash/trait.Hash.html#tymethod.hash">Read more</a></p>
</div><h4 id='method.hash_slice' class="method"><code id='hash_slice.v'>fn <a href='../../std/hash/trait.Hash.html#method.hash_slice' class='fnname'>hash_slice</a>&lt;H&gt;(data: <a class="primitive" href="../primitive.slice.html">&amp;[Self]</a>, state: <a class="primitive" href="../primitive.reference.html">&amp;mut </a>H) <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;H: <a class="trait" href="../../std/hash/trait.Hasher.html" title="trait std::hash::Hasher">Hasher</a>,&nbsp;</span></code><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div><a class='srclink' href='../../src/core/hash/mod.rs.html#193-199' title='goto source code'>[src]</a></h4><div class='docblock'><p>Feeds a slice of this type into the given [<code>Hasher</code>]. <a href="../../std/hash/trait.Hash.html#method.hash_slice">Read more</a></p>
</div></div><h3 id='impl-AsRef%3CCStr%3E' class='impl'><code class='in-band'>impl <a class="trait" href="../../std/convert/trait.AsRef.html" title="trait std::convert::AsRef">AsRef</a>&lt;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>&gt; for <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><a href='#impl-AsRef%3CCStr%3E' class='anchor'></a><div class='since' title='Stable since Rust version 1.7.0'>1.7.0</div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1288-1293' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.as_ref' class="method hidden"><code id='as_ref.v'>fn <a href='../../std/convert/trait.AsRef.html#tymethod.as_ref' class='fnname'>as_ref</a>(&amp;self) -&gt; &amp;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1290-1292' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
</div></div><h3 id='impl-AsRef%3CCStr%3E-1' class='impl'><code class='in-band'>impl <a class="trait" href="../../std/convert/trait.AsRef.html" title="trait std::convert::AsRef">AsRef</a>&lt;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>&gt; for <a class="struct" href="../../std/ffi/struct.CString.html" title="struct std::ffi::CString">CString</a></code><a href='#impl-AsRef%3CCStr%3E-1' class='anchor'></a><div class='since' title='Stable since Rust version 1.7.0'>1.7.0</div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1296-1301' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.as_ref-1' class="method hidden"><code id='as_ref.v-1'>fn <a href='../../std/convert/trait.AsRef.html#tymethod.as_ref' class='fnname'>as_ref</a>(&amp;self) -&gt; &amp;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1298-1300' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
</div></div><h3 id='impl-Default' class='impl'><code class='in-band'>impl&lt;'_&gt; <a class="trait" href="../../std/default/trait.Default.html" title="trait std::default::Default">Default</a> for &amp;'_ <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><a href='#impl-Default' class='anchor'></a><div class='since' title='Stable since Rust version 1.10.0'>1.10.0</div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#662-667' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.default' class="method hidden"><code id='default.v'>fn <a href='../../std/default/trait.Default.html#tymethod.default' class='fnname'>default</a>() -&gt; Self</code><a class='srclink' href='../../src/std/ffi/c_str.rs.html#663-666' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Returns the &quot;default value&quot; for a type. <a href="../../std/default/trait.Default.html#tymethod.default">Read more</a></p>
</div></div><h3 id='impl-Borrow%3CCStr%3E' class='impl'><code class='in-band'>impl <a class="trait" href="../../std/borrow/trait.Borrow.html" title="trait std::borrow::Borrow">Borrow</a>&lt;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>&gt; for <a class="struct" href="../../std/ffi/struct.CString.html" title="struct std::ffi::CString">CString</a></code><a href='#impl-Borrow%3CCStr%3E' class='anchor'></a><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#679-682' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.borrow' class="method hidden"><code id='borrow.v'>fn <a href='../../std/borrow/trait.Borrow.html#tymethod.borrow' class='fnname'>borrow</a>(&amp;self) -&gt; &amp;<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><a class='srclink' href='../../src/std/ffi/c_str.rs.html#681' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Immutably borrows from an owned value. <a href="../../std/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p>
</div></div><h3 id='impl-ToOwned' class='impl'><code class='in-band'>impl <a class="trait" href="../../std/borrow/trait.ToOwned.html" title="trait std::borrow::ToOwned">ToOwned</a> for <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><a href='#impl-ToOwned' class='anchor'></a><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1262-1268' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Owned' class="type"><code id='Owned.t'>type <a href='../../std/borrow/trait.ToOwned.html#associatedtype.Owned' class="type">Owned</a> = <a class="struct" href="../../std/ffi/struct.CString.html" title="struct std::ffi::CString">CString</a></code></h4><h4 id='method.to_owned' class="method hidden"><code id='to_owned.v'>fn <a href='../../std/borrow/trait.ToOwned.html#tymethod.to_owned' class='fnname'>to_owned</a>(&amp;self) -&gt; <a class="struct" href="../../std/ffi/struct.CString.html" title="struct std::ffi::CString">CString</a></code><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1265-1267' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Creates owned data from borrowed data, usually by cloning. <a href="../../std/borrow/trait.ToOwned.html#tymethod.to_owned">Read more</a></p>
</div><h4 id='method.clone_into' class="method"><code id='clone_into.v'>fn <a href='../../std/borrow/trait.ToOwned.html#method.clone_into' class='fnname'>clone_into</a>(&amp;self, target: &amp;mut Self::<a class="type" href="../../std/borrow/trait.ToOwned.html#associatedtype.Owned" title="type std::borrow::ToOwned::Owned">Owned</a>)</code><a class='srclink' href='../../src/alloc/borrow.rs.html#74-76' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><details><summary><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>toowned_clone_into</code>&nbsp;<a href="https://github.com/rust-lang/rust/issues/41263">#41263</a>)</summary><p>recently added</p>
</details></div></div><div class='docblock'><p>Uses borrowed data to replace owned data, usually by cloning. <a href="../../std/borrow/trait.ToOwned.html#method.clone_into">Read more</a></p>
</div></div></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'><h3 id='impl-Send' class='impl'><code class='in-band'>impl <a class="trait" href="../../std/marker/trait.Send.html" title="trait std::marker::Send">Send</a> for <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><a href='#impl-Send' class='anchor'></a></h3><div class='impl-items'></div><h3 id='impl-Sync' class='impl'><code class='in-band'>impl <a class="trait" href="../../std/marker/trait.Sync.html" title="trait std::marker::Sync">Sync</a> for <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><a href='#impl-Sync' class='anchor'></a></h3><div class='impl-items'></div></div><h2 id='blanket-implementations' class='small-section-header'>Blanket Implementations<a href='#blanket-implementations' class='anchor'></a></h2><div id='blanket-implementations-list'><h3 id='impl-Borrow' class='impl'><code class='in-band'>impl&lt;T&gt; <a class="trait" href="../../std/borrow/trait.Borrow.html" title="trait std::borrow::Borrow">Borrow</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,&nbsp;</span></code><a href='#impl-Borrow' class='anchor'></a><a class='srclink' href='../../src/core/borrow.rs.html#213-215' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.borrow-1' class="method hidden"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>F</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>F</h3><code class="content"><span class="where fmt-newline">impl&lt;'_, F&gt; <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>F <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="../../std/marker/trait.Unpin.html" title="trait std::marker::Unpin">Unpin</a> + <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,&nbsp;</span></span><span class="where fmt-newline">    type <a href='../../std/future/trait.Future.html#associatedtype.Output' class="type">Output</a> = &lt;F as <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a>&gt;::<a class="type" href="../../std/future/trait.Future.html#associatedtype.Output" title="type std::future::Future::Output">Output</a>;</span><span class="where fmt-newline">impl&lt;'_, I&gt; <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>I <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,&nbsp;</span></span><span class="where fmt-newline">    type <a href='../../std/iter/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = &lt;I as <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a>&gt;::<a class="type" href="../../std/iter/trait.Iterator.html#associatedtype.Item" title="type std::iter::Iterator::Item">Item</a>;</span><span class="where fmt-newline">impl&lt;R:&nbsp;<a class="trait" href="../../std/io/trait.Read.html" title="trait std::io::Read">Read</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, '_&gt; <a class="trait" href="../../std/io/trait.Read.html" title="trait std::io::Read">Read</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>R</span><span class="where fmt-newline">impl&lt;W:&nbsp;<a class="trait" href="../../std/io/trait.Write.html" title="trait std::io::Write">Write</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, '_&gt; <a class="trait" href="../../std/io/trait.Write.html" title="trait std::io::Write">Write</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>W</span></code></div></div><code id='borrow.v-1'>fn <a href='../../std/borrow/trait.Borrow.html#tymethod.borrow' class='fnname'>borrow</a>(&amp;self) -&gt; <a class="primitive" href="../primitive.reference.html">&amp;</a>T</code><a class='srclink' href='../../src/core/borrow.rs.html#214' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Immutably borrows from an owned value. <a href="../../std/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p>
</div></div><h3 id='impl-BorrowMut' class='impl'><code class='in-band'>impl&lt;T&gt; <a class="trait" href="../../std/borrow/trait.BorrowMut.html" title="trait std::borrow::BorrowMut">BorrowMut</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,&nbsp;</span></code><a href='#impl-BorrowMut' class='anchor'></a><a class='srclink' href='../../src/core/borrow.rs.html#218-220' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.borrow_mut' class="method hidden"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>F</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>F</h3><code class="content"><span class="where fmt-newline">impl&lt;'_, F&gt; <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>F <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="../../std/marker/trait.Unpin.html" title="trait std::marker::Unpin">Unpin</a> + <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,&nbsp;</span></span><span class="where fmt-newline">    type <a href='../../std/future/trait.Future.html#associatedtype.Output' class="type">Output</a> = &lt;F as <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a>&gt;::<a class="type" href="../../std/future/trait.Future.html#associatedtype.Output" title="type std::future::Future::Output">Output</a>;</span><span class="where fmt-newline">impl&lt;'_, I&gt; <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>I <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,&nbsp;</span></span><span class="where fmt-newline">    type <a href='../../std/iter/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = &lt;I as <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a>&gt;::<a class="type" href="../../std/iter/trait.Iterator.html#associatedtype.Item" title="type std::iter::Iterator::Item">Item</a>;</span><span class="where fmt-newline">impl&lt;R:&nbsp;<a class="trait" href="../../std/io/trait.Read.html" title="trait std::io::Read">Read</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, '_&gt; <a class="trait" href="../../std/io/trait.Read.html" title="trait std::io::Read">Read</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>R</span><span class="where fmt-newline">impl&lt;W:&nbsp;<a class="trait" href="../../std/io/trait.Write.html" title="trait std::io::Write">Write</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, '_&gt; <a class="trait" href="../../std/io/trait.Write.html" title="trait std::io::Write">Write</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>W</span></code></div></div><code id='borrow_mut.v'>fn <a href='../../std/borrow/trait.BorrowMut.html#tymethod.borrow_mut' class='fnname'>borrow_mut</a>(&amp;mut self) -&gt; <a class="primitive" href="../primitive.reference.html">&amp;mut </a>T</code><a class='srclink' href='../../src/core/borrow.rs.html#219' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Mutably borrows from an owned value. <a href="../../std/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></p>
</div></div><h3 id='impl-Any' class='impl'><code class='in-band'>impl&lt;T&gt; <a class="trait" href="../../std/any/trait.Any.html" title="trait std::any::Any">Any</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'static + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,&nbsp;</span></code><a href='#impl-Any' class='anchor'></a><a class='srclink' href='../../src/core/any.rs.html#100-102' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.type_id' class="method hidden"><code id='type_id.v'>fn <a href='../../std/any/trait.Any.html#tymethod.type_id' class='fnname'>type_id</a>(&amp;self) -&gt; <a class="struct" href="../../std/any/struct.TypeId.html" title="struct std::any::TypeId">TypeId</a></code><a class='srclink' href='../../src/core/any.rs.html#101' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Gets the <code>TypeId</code> of <code>self</code>. <a href="../../std/any/trait.Any.html#tymethod.type_id">Read more</a></p>
</div></div><h3 id='impl-ToOwned-1' class='impl'><code class='in-band'>impl&lt;T&gt; <a class="trait" href="../../std/borrow/trait.ToOwned.html" title="trait std::borrow::ToOwned">ToOwned</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../std/clone/trait.Clone.html" title="trait std::clone::Clone">Clone</a>,&nbsp;</span></code><a href='#impl-ToOwned-1' class='anchor'></a><a class='srclink' href='../../src/alloc/borrow.rs.html#80-91' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Owned-1' class="type"><code id='Owned.t-1'>type <a href='../../std/borrow/trait.ToOwned.html#associatedtype.Owned' class="type">Owned</a> = T</code></h4><h4 id='method.to_owned-1' class="method hidden"><code id='to_owned.v-1'>fn <a href='../../std/borrow/trait.ToOwned.html#tymethod.to_owned' class='fnname'>to_owned</a>(&amp;self) -&gt; T</code><a class='srclink' href='../../src/alloc/borrow.rs.html#84-86' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Creates owned data from borrowed data, usually by cloning. <a href="../../std/borrow/trait.ToOwned.html#tymethod.to_owned">Read more</a></p>
</div><h4 id='method.clone_into-1' class="method hidden"><code id='clone_into.v-1'>fn <a href='../../std/borrow/trait.ToOwned.html#method.clone_into' class='fnname'>clone_into</a>(&amp;self, target: <a class="primitive" href="../primitive.reference.html">&amp;mut </a>T)</code><a class='srclink' href='../../src/alloc/borrow.rs.html#88-90' title='goto source code'>[src]</a></h4><div class='stability hidden'><div class='stab unstable'><details><summary><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>toowned_clone_into</code>&nbsp;<a href="https://github.com/rust-lang/rust/issues/41263">#41263</a>)</summary><p>recently added</p>
</details></div></div><div class='docblock hidden'><p>Uses borrowed data to replace owned data, usually by cloning. <a href="../../std/borrow/trait.ToOwned.html#method.clone_into">Read more</a></p>
</div></div></div></section><section id="search" class="content hidden"></section><section class="footer"></section><aside id="help" class="hidden"><div><h1 class="hidden">Help</h1><div class="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd>↑</kbd></dt><dd>Move up in search results</dd><dt><kbd>↓</kbd></dt><dd>Move down in search results</dd><dt><kbd>↹</kbd></dt><dd>Switch tab</dd><dt><kbd>&#9166;</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse all sections</dd></dl></div><div class="infos"><h2>Search Tricks</h2><p>Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to restrict the search to a given type.</p><p>Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>.</p><p>Search functions by type signature (e.g., <code>vec -> usize</code> or <code>* -> vec</code>)</p><p>Search multiple things at once by splitting your query with comma (e.g., <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../../";window.currentCrate = "std";</script><script src="../../aliases.js"></script><script src="../../main1.35.0.js"></script><script defer src="../../search-index.js"></script></body></html>