<!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="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><script src="../../storage.js"></script><link rel="shortcut icon" href="https://doc.rust-lang.org/favicon.ico"></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">☰</div><a href='../../std/index.html'><img src='https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.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.from_ptr">from_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.as_ptr">as_ptr</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><a href="#method.into_c_string">into_c_string</a></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Hash">Hash</a><a href="#impl-Debug">Debug</a><a href="#impl-Default">Default</a><a href="#impl-Borrow%3CCStr%3E">Borrow<CStr></a><a href="#impl-From%3C%26%27a%20CStr%3E">From<&'a CStr></a><a href="#impl-PartialEq">PartialEq</a><a href="#impl-Eq">Eq</a><a href="#impl-PartialOrd">PartialOrd</a><a href="#impl-Ord">Ord</a><a href="#impl-ToOwned">ToOwned</a><a href="#impl-AsRef%3CCStr%3E">AsRef<CStr></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></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="../../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../../theme.js"></script><nav class="sub"><form class="search-form js-only"><div class="search-container"><input class="search-input" name="search" autocomplete="off" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><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><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'>−</span>]</a></span><a class='srclink' href='../../src/std/ffi/c_str.rs.html#205-211' title='goto source code'>[src]</a></span></h1><div class="docblock type-decl"><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>&[</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>&str</code></a> by performing UTF-8 validation, or into an owned <a href="struct.CString.html"><code>CString</code></a>.</p> <p><code>CStr</code> is to <a href="struct.CString.html"><code>CString</code></a> as <a href="../primitive.str.html"><code>&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><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">-></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">"string buffer size without nul terminator: {}"</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> <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><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">&</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">"data data data data"</span>).<span class="ident">unwrap</span>(); <span class="ident">work</span>(<span class="kw-2">&</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).unwrap()%3B%0Awork(%26s)%3B%0A%7D">Run</a></pre> <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><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">-></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">-></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">"string: {}"</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> <h2 id='methods' class='small-section-header'> Methods<a href='#methods' class='anchor'></a> </h2> <h3 id='impl' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><a href='#impl' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#898-1207' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from_ptr' class="method"><span id='from_ptr.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub unsafe fn <a href='#method.from_ptr' class='fnname'>from_ptr</a><'a>(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>) -> &'a <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#935-939' title='goto source code'>[src]</a></td></tr></tbody></table></span></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><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">-></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">"string returned: {}"</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><h4 id='method.from_bytes_with_nul' class="method"><span id='from_bytes_with_nul.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.from_bytes_with_nul' class='fnname'>from_bytes_with_nul</a>(bytes: <a class="primitive" href="../primitive.slice.html">&[</a><a class="primitive" href="../primitive.u8.html">u8</a><a class="primitive" href="../primitive.slice.html">]</a>) -> <a class="enum" href="../../std/result/enum.Result.html" title="enum std::result::Result">Result</a><&<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>></code></span></td><td><span class='out-of-band'><div class='ghost'></div><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#974-985' title='goto source code'>[src]</a></td></tr></tbody></table></span></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> <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"hello\0"</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> <p>Creating a <code>CStr</code> without a trailing nul terminator is an error:</p> <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"hello"</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> <p>Creating a <code>CStr</code> with an interior nul byte is an error:</p> <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"he\0llo\0"</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><h4 id='method.from_bytes_with_nul_unchecked' class="method"><span id='from_bytes_with_nul_unchecked.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub 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">&[</a><a class="primitive" href="../primitive.u8.html">u8</a><a class="primitive" href="../primitive.slice.html">]</a>) -> &<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><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#1006-1008' title='goto source code'>[src]</a></td></tr></tbody></table></span></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> <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">"hello"</span>).<span class="ident">unwrap</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">&</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).unwrap()%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><h4 id='method.as_ptr' class="method"><span id='as_ptr.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.as_ptr' class='fnname'>as_ptr</a>(&self) -> <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></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1056-1058' title='goto source code'>[src]</a></td></tr></tbody></table></span></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> <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">"Hello"</span>).<span class="ident">unwrap</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).unwrap().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> <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("Hello").unwrap().as_ptr()</code> expression is evaluated. To fix the problem, bind the <code>CString</code> to a local variable:</p> <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">"Hello"</span>).<span class="ident">unwrap</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).unwrap()%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> <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">&'a [</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">&'a [</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<'a> <a class="trait" href="../../std/io/trait.Read.html" title="trait std::io::Read">Read</a> for <a class="primitive" href="../primitive.slice.html">&'a [</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<'a> <a class="trait" href="../../std/io/trait.Write.html" title="trait std::io::Write">Write</a> for <a class="primitive" href="../primitive.slice.html">&'a mut [</a><a class="primitive" href="../primitive.u8.html">u8</a><a class="primitive" href="../primitive.slice.html">]</a></span></code></div></div><span id='to_bytes.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.to_bytes' class='fnname'>to_bytes</a>(&self) -> <a class="primitive" href="../primitive.slice.html">&[</a><a class="primitive" href="../primitive.u8.html">u8</a><a class="primitive" href="../primitive.slice.html">]</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1079-1082' title='goto source code'>[src]</a></td></tr></tbody></table></span></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> <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"foo\0"</span>).<span class="ident">unwrap</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"foo"</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).unwrap()%3B%0Aassert_eq!(c_str.to_bytes()%2C%20b%22foo%22)%3B%0A%7D">Run</a></pre> </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">&'a [</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">&'a [</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<'a> <a class="trait" href="../../std/io/trait.Read.html" title="trait std::io::Read">Read</a> for <a class="primitive" href="../primitive.slice.html">&'a [</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<'a> <a class="trait" href="../../std/io/trait.Write.html" title="trait std::io::Write">Write</a> for <a class="primitive" href="../primitive.slice.html">&'a mut [</a><a class="primitive" href="../primitive.u8.html">u8</a><a class="primitive" href="../primitive.slice.html">]</a></span></code></div></div><span id='to_bytes_with_nul.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.to_bytes_with_nul' class='fnname'>to_bytes_with_nul</a>(&self) -> <a class="primitive" href="../primitive.slice.html">&[</a><a class="primitive" href="../primitive.u8.html">u8</a><a class="primitive" href="../primitive.slice.html">]</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1105-1107' title='goto source code'>[src]</a></td></tr></tbody></table></span></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> <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"foo\0"</span>).<span class="ident">unwrap</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"foo\0"</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).unwrap()%3B%0Aassert_eq!(c_str.to_bytes_with_nul()%2C%20b%22foo%5C0%22)%3B%0A%7D">Run</a></pre> </div><h4 id='method.to_str' class="method"><span id='to_str.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.to_str' class='fnname'>to_str</a>(&self) -> <a class="enum" href="../../std/result/enum.Result.html" title="enum std::result::Result">Result</a><&<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>></code></span></td><td><span class='out-of-band'><div class='ghost'></div><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#1131-1137' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Yields a <a href="../primitive.str.html"><code>&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>&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> <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"foo\0"</span>).<span class="ident">unwrap</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">"foo"</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).unwrap()%3B%0Aassert_eq!(c_str.to_str()%2C%20Ok(%22foo%22))%3B%0A%7D">Run</a></pre> </div><h4 id='method.to_string_lossy' class="method"><span id='to_string_lossy.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.to_string_lossy' class='fnname'>to_string_lossy</a>(&self) -> <a class="enum" href="../../std/borrow/enum.Cow.html" title="enum std::borrow::Cow">Cow</a><<a class="primitive" href="../primitive.str.html">str</a>></code></span></td><td><span class='out-of-band'><div class='ghost'></div><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#1184-1186' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Converts a <code>CStr</code> into a <a href="../borrow/enum.Cow.html"><code>Cow</code></a><code><</code><a href="../primitive.str.html"><code>str</code></a><code>></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>&str</code>]<code>)</code> with the the corresponding [<code>&str</code>] slice. Otherwise, it will replace any invalid UTF-8 sequences with <code>U+FFFD REPLACEMENT CHARACTER</code> 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> <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"Hello World\0"</span>).<span class="ident">unwrap</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">"Hello World"</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).unwrap()%3B%0Aassert_eq!(c_str.to_string_lossy()%2C%20Cow%3A%3ABorrowed(%22Hello%20World%22))%3B%0A%7D">Run</a></pre> <p>Calling <code>to_string_lossy</code> on a <code>CStr</code> containing invalid UTF-8:</p> <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"Hello \xF0\x90\x80World\0"</span>).<span class="ident">unwrap</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">"Hello �World"</span>)) <span class="kw">as</span> <span class="ident">Cow</span><span class="op"><</span><span class="ident">str</span><span class="op">></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).unwrap()%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%3Cstr%3E%0A)%3B%0A%7D">Run</a></pre> </div><h4 id='method.into_c_string' class="method"><span id='into_c_string.v' class='invisible'><table class='table-display'><tbody><tr><td><code>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><<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>>) -> <a class="struct" href="../../std/ffi/struct.CString.html" title="struct std::ffi::CString">CString</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><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#1203-1206' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Converts a <a href="../boxed/struct.Box.html"><code>Box</code></a><code><CStr></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> <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"foo"</span>.<span class="ident">to_vec</span>()).<span class="ident">unwrap</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">"foo"</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%3ACString%3B%0A%0Alet%20c_string%20%3D%20CString%3A%3Anew(b%22foo%22.to_vec()).unwrap()%3B%0Alet%20boxed%20%3D%20c_string.into_boxed_c_str()%3B%0Aassert_eq!(boxed.into_c_string()%2C%20CString%3A%3Anew(%22foo%22).unwrap())%3B%0A%7D">Run</a></pre> </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-Hash' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>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></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#203' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.hash' class="method"><span id='hash.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/hash/trait.Hash.html#tymethod.hash' class='fnname'>hash</a><__H: <a class="trait" href="../../std/hash/trait.Hasher.html" title="trait std::hash::Hasher">Hasher</a>>(&self, state: <a class="primitive" href="../primitive.reference.html">&mut </a>__H)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#203' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><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"><span id='hash_slice.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/hash/trait.Hash.html#method.hash_slice' class='fnname'>hash_slice</a><H>(data: <a class="primitive" href="../primitive.slice.html">&[Self]</a>, state: <a class="primitive" href="../primitive.reference.html">&mut </a>H) <span class="where fmt-newline">where<br> H: <a class="trait" href="../../std/hash/trait.Hasher.html" title="trait std::hash::Hasher">Hasher</a>, </span></code></span></td><td><span class='out-of-band'><div class='ghost'></div><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#203-209' title='goto source code'>[src]</a></td></tr></tbody></table></span></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-Debug' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>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></span></td><td><span class='out-of-band'><div class='ghost'></div><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#652-660' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&self, f: &mut <a class="struct" href="../../std/fmt/struct.Formatter.html" title="struct std::fmt::Formatter">Formatter</a>) -> <a class="type" href="../../std/fmt/type.Result.html" title="type std::fmt::Result">Result</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#653-659' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><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-Default' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a> <a class="trait" href="../../std/default/trait.Default.html" title="trait std::default::Default">Default</a> for &'a <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><a href='#impl-Default' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><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#663-668' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.default' class="method"><span id='default.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/default/trait.Default.html#tymethod.default' class='fnname'>default</a>() -> &'a <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#664-667' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Returns the "default value" 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'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../std/borrow/trait.Borrow.html" title="trait std::borrow::Borrow">Borrow</a><<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>> 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></span></td><td><span class='out-of-band'><div class='ghost'></div><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#680-683' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.borrow' class="method"><span id='borrow.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/borrow/trait.Borrow.html#tymethod.borrow' class='fnname'>borrow</a>(&self) -> &<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#682' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><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-From%3C%26%27a%20CStr%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a> <a class="trait" href="../../std/convert/trait.From.html" title="trait std::convert::From">From</a><&'a <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>> for <a class="struct" href="../../std/boxed/struct.Box.html" title="struct std::boxed::Box">Box</a><<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>></code><a href='#impl-From%3C%26%27a%20CStr%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><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#694-699' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from' class="method"><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><I></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><I></h3><code class="content"><span class="where fmt-newline">impl<I> <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><I> <span class="where fmt-newline">where<br> 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>, </span></span><span class="where fmt-newline"> type <a href='../../std/iter/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = <I as <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a>>::<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<R: <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>> <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><R></span><span class="where fmt-newline">impl<W: <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>> <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><W></span></code></div></div><span id='from.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(s: &'a <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>) -> <a class="struct" href="../../std/boxed/struct.Box.html" title="struct std::boxed::Box">Box</a><<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#695-698' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the conversion.</p> </div></div><h3 id='impl-From%3C%26%27a%20CStr%3E-1' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a> <a class="trait" href="../../std/convert/trait.From.html" title="trait std::convert::From">From</a><&'a <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>> for <a class="enum" href="../../std/borrow/enum.Cow.html" title="enum std::borrow::Cow">Cow</a><'a, <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>></code><a href='#impl-From%3C%26%27a%20CStr%3E-1' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><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#726-731' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from-1' class="method"><span id='from.v-1' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(s: &'a <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>) -> <a class="enum" href="../../std/borrow/enum.Cow.html" title="enum std::borrow::Cow">Cow</a><'a, <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#728-730' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the conversion.</p> </div></div><h3 id='impl-From%3C%26%27a%20CStr%3E-2' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a> <a class="trait" href="../../std/convert/trait.From.html" title="trait std::convert::From">From</a><&'a <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>> for <a class="struct" href="../../std/sync/struct.Arc.html" title="struct std::sync::Arc">Arc</a><<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>></code><a href='#impl-From%3C%26%27a%20CStr%3E-2' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><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#751-757' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from-2' class="method"><span id='from.v-2' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(s: &<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>) -> <a class="struct" href="../../std/sync/struct.Arc.html" title="struct std::sync::Arc">Arc</a><<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#753-756' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the conversion.</p> </div></div><h3 id='impl-From%3C%26%27a%20CStr%3E-3' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a> <a class="trait" href="../../std/convert/trait.From.html" title="trait std::convert::From">From</a><&'a <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>> for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>></code><a href='#impl-From%3C%26%27a%20CStr%3E-3' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><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#769-775' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from-3' class="method"><span id='from.v-3' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(s: &<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>) -> <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#771-774' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the conversion.</p> </div></div><h3 id='impl-PartialEq' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../std/cmp/trait.PartialEq.html" title="trait std::cmp::PartialEq">PartialEq</a> for <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><a href='#impl-PartialEq' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1210-1214' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.eq' class="method"><span id='eq.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&self, other: &<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1211-1213' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../../std/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p> </div><h4 id='method.ne' class="method"><span id='ne.v' class='invisible'><table class='table-display'><tbody><tr><td><code><div class="docblock attributes">#[must_use] </div>fn <a href='../../std/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&self, other: <a class="primitive" href="../primitive.reference.html">&</a>Rhs) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/cmp.rs.html#123' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>This method tests for <code>!=</code>.</p> </div></div><h3 id='impl-Eq' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>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></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1216' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'></div><h3 id='impl-PartialOrd' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../std/cmp/trait.PartialOrd.html" title="trait std::cmp::PartialOrd">PartialOrd</a> for <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code><a href='#impl-PartialOrd' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1218-1222' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.partial_cmp' class="method"><span id='partial_cmp.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/cmp/trait.PartialOrd.html#tymethod.partial_cmp' class='fnname'>partial_cmp</a>(&self, other: &<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>) -> <a class="enum" href="../../std/option/enum.Option.html" title="enum std::option::Option">Option</a><<a class="enum" href="../../std/cmp/enum.Ordering.html" title="enum std::cmp::Ordering">Ordering</a>></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1219-1221' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><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"><span id='lt.v' class='invisible'><table class='table-display'><tbody><tr><td><code><div class="docblock attributes">#[must_use] </div>fn <a href='../../std/cmp/trait.PartialOrd.html#method.lt' class='fnname'>lt</a>(&self, other: <a class="primitive" href="../primitive.reference.html">&</a>Rhs) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/cmp.rs.html#657-662' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>This method tests less than (for <code>self</code> and <code>other</code>) and is used by the <code><</code> operator. <a href="../../std/cmp/trait.PartialOrd.html#method.lt">Read more</a></p> </div><h4 id='method.le' class="method"><span id='le.v' class='invisible'><table class='table-display'><tbody><tr><td><code><div class="docblock attributes">#[must_use] </div>fn <a href='../../std/cmp/trait.PartialOrd.html#method.le' class='fnname'>le</a>(&self, other: <a class="primitive" href="../primitive.reference.html">&</a>Rhs) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/cmp.rs.html#679-684' title='goto source code'>[src]</a></td></tr></tbody></table></span></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><=</code> operator. <a href="../../std/cmp/trait.PartialOrd.html#method.le">Read more</a></p> </div><h4 id='method.gt' class="method"><span id='gt.v' class='invisible'><table class='table-display'><tbody><tr><td><code><div class="docblock attributes">#[must_use] </div>fn <a href='../../std/cmp/trait.PartialOrd.html#method.gt' class='fnname'>gt</a>(&self, other: <a class="primitive" href="../primitive.reference.html">&</a>Rhs) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/cmp.rs.html#700-705' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>This method tests greater than (for <code>self</code> and <code>other</code>) and is used by the <code>></code> operator. <a href="../../std/cmp/trait.PartialOrd.html#method.gt">Read more</a></p> </div><h4 id='method.ge' class="method"><span id='ge.v' class='invisible'><table class='table-display'><tbody><tr><td><code><div class="docblock attributes">#[must_use] </div>fn <a href='../../std/cmp/trait.PartialOrd.html#method.ge' class='fnname'>ge</a>(&self, other: <a class="primitive" href="../primitive.reference.html">&</a>Rhs) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/cmp.rs.html#722-727' title='goto source code'>[src]</a></td></tr></tbody></table></span></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>>=</code> operator. <a href="../../std/cmp/trait.PartialOrd.html#method.ge">Read more</a></p> </div></div><h3 id='impl-Ord' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>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></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1224-1228' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.cmp' class="method"><span id='cmp.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/cmp/trait.Ord.html#tymethod.cmp' class='fnname'>cmp</a>(&self, other: &<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>) -> <a class="enum" href="../../std/cmp/enum.Ordering.html" title="enum std::cmp::Ordering">Ordering</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1225-1227' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><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"><span id='max.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/cmp/trait.Ord.html#method.max' class='fnname'>max</a>(self, other: Self) -> Self</code></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.21.0'>1.21.0</div><a class='srclink' href='../../src/core/cmp.rs.html#469-472' title='goto source code'>[src]</a></td></tr></tbody></table></span></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"><span id='min.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/cmp/trait.Ord.html#method.min' class='fnname'>min</a>(self, other: Self) -> Self</code></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.21.0'>1.21.0</div><a class='srclink' href='../../src/core/cmp.rs.html#485-488' title='goto source code'>[src]</a></td></tr></tbody></table></span></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></div><h3 id='impl-ToOwned' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>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></span></td><td><span class='out-of-band'><div class='ghost'></div><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#1231-1237' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='associatedtype.Owned' class="type"><span id='Owned.t' class='invisible'><code>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></span></h4> <h4 id='method.to_owned' class="method"><span id='to_owned.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/borrow/trait.ToOwned.html#tymethod.to_owned' class='fnname'>to_owned</a>(&self) -> <a class="struct" href="../../std/ffi/struct.CString.html" title="struct std::ffi::CString">CString</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1234-1236' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><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"><span id='clone_into.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/borrow/trait.ToOwned.html#method.clone_into' class='fnname'>clone_into</a>(&self, target: &mut Self::<a class="type" href="../../std/borrow/trait.ToOwned.html#associatedtype.Owned" title="type std::borrow::ToOwned::Owned">Owned</a>)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/borrow.rs.html#84-86' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='stability'><div class='stab unstable'><details><summary><span class=microscope>🔬</span> This is a nightly-only experimental API. (<code>toowned_clone_into </code><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><h3 id='impl-From%3C%26%27a%20CStr%3E-4' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl<'a> <a class="trait" href="../../std/convert/trait.From.html" title="trait std::convert::From">From</a><&'a <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>> for <a class="struct" href="../../std/ffi/struct.CString.html" title="struct std::ffi::CString">CString</a></code><a href='#impl-From%3C%26%27a%20CStr%3E-4' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><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#1240-1244' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from-4' class="method"><span id='from.v-4' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(s: &'a <a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>) -> <a class="struct" href="../../std/ffi/struct.CString.html" title="struct std::ffi::CString">CString</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1241-1243' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the conversion.</p> </div></div><h3 id='impl-AsRef%3CCStr%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../std/convert/trait.AsRef.html" title="trait std::convert::AsRef">AsRef</a><<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>> 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></span></td><td><span class='out-of-band'><div class='ghost'></div><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#1257-1262' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.as_ref' class="method"><span id='as_ref.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/convert/trait.AsRef.html#tymethod.as_ref' class='fnname'>as_ref</a>(&self) -> &<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1259-1261' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the conversion.</p> </div></div><h3 id='impl-AsRef%3CCStr%3E-1' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="../../std/convert/trait.AsRef.html" title="trait std::convert::AsRef">AsRef</a><<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a>> 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></span></td><td><span class='out-of-band'><div class='ghost'></div><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#1265-1270' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.as_ref-1' class="method"><span id='as_ref.v-1' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../std/convert/trait.AsRef.html#tymethod.as_ref' class='fnname'>as_ref</a>(&self) -> &<a class="struct" href="../../std/ffi/struct.CStr.html" title="struct std::ffi::CStr">CStr</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/ffi/c_str.rs.html#1267-1269' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the conversion.</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'><span class='in-band'><table class='table-display'><tbody><tr><td><code>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></span></td><td><span class='out-of-band'></span></td></tr></tbody></table></h3><div class='impl-items'></div><h3 id='impl-Sync' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>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></span></td><td><span class='out-of-band'></span></td></tr></tbody></table></h3><div class='impl-items'></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>⏎</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="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>