|
|
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Representation of a borrowed C string."><title>CStr in rustix::ffi - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-ac92e1bbe349e143.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="rustix" data-themes="" data-resource-suffix="" data-rustdoc-version="1.76.0 (07dca489a 2024-02-04)" data-channel="1.76.0" data-search-js="search-2b6ce74ff89ae146.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../static.files/storage-f2adc0d6ca4d09fb.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-305769736d49e732.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-feafe1bb7466e4bd.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc struct"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../rustix/index.html">rustix</a><span class="version">0.38.34</span></h2></div><h2 class="location"><a href="#">CStr</a></h2><div class="sidebar-elems"><section><h3><a href="#implementations">Methods</a></h3><ul class="block method"><li><a href="#method.as_ptr">as_ptr</a></li><li><a href="#method.count_bytes">count_bytes</a></li><li><a href="#method.from_bytes_until_nul">from_bytes_until_nul</a></li><li><a href="#method.from_bytes_with_nul">from_bytes_with_nul</a></li><li><a href="#method.from_bytes_with_nul_unchecked">from_bytes_with_nul_unchecked</a></li><li><a href="#method.from_ptr">from_ptr</a></li><li><a href="#method.into_c_string">into_c_string</a></li><li><a href="#method.is_empty">is_empty</a></li><li><a href="#method.to_bytes">to_bytes</a></li><li><a href="#method.to_bytes_with_nul">to_bytes_with_nul</a></li><li><a href="#method.to_str">to_str</a></li><li><a href="#method.to_string_lossy">to_string_lossy</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-AsRef%3CCStr%3E-for-CStr">AsRef<CStr></a></li><li><a href="#impl-AsRef%3CCStr%3E-for-CString">AsRef<CStr></a></li><li><a href="#impl-Borrow%3CCStr%3E-for-CString">Borrow<CStr></a></li><li><a href="#impl-Debug-for-CStr">Debug</a></li><li><a href="#impl-Default-for-%26CStr">Default</a></li><li><a href="#impl-Eq-for-CStr">Eq</a></li><li><a href="#impl-From%3C%26CStr%3E-for-CString">From<&CStr></a></li><li><a href="#impl-Hash-for-CStr">Hash</a></li><li><a href="#impl-Index%3CRangeFrom%3Cusize%3E%3E-for-CStr">Index<RangeFrom<usize>></a></li><li><a href="#impl-Ord-for-CStr">Ord</a></li><li><a href="#impl-PartialEq-for-CStr">PartialEq</a></li><li><a href="#impl-PartialOrd-for-CStr">PartialOrd</a></li><li><a href="#impl-ToOwned-for-CStr">ToOwned</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-Sized-for-CStr">!Sized</a></li><li><a href="#impl-RefUnwindSafe-for-CStr">RefUnwindSafe</a></li><li><a href="#impl-Send-for-CStr">Send</a></li><li><a href="#impl-Sync-for-CStr">Sync</a></li><li><a href="#impl-Unpin-for-CStr">Unpin</a></li><li><a href="#impl-UnwindSafe-for-CStr">UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block blanket-implementation"><li><a href="#impl-Any-for-T">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-T">Borrow<T></a></li><li><a href="#impl-BorrowMut%3CT%3E-for-T">BorrowMut<T></a></li></ul></section><h2><a href="index.html">In rustix::ffi</a></h2></div></nav><div class="sidebar-resizer"></div>
|
|
|
<main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><div id="sidebar-button" tabindex="-1"><a href="../../rustix/all.html" title="show sidebar"></a></div><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" tabindex="-1"><a href="../../help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Struct <a href="../index.html">rustix</a>::<wbr><a href="index.html">ffi</a>::<wbr><a class="struct" href="#">CStr</a><button id="copy-path" title="Copy item path to clipboard"><img src="../../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><span class="since" title="Stable since Rust version 1.64.0">1.64.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#91">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><pre class="rust item-decl"><code>pub struct CStr { <span class="comment">/* private fields */</span> }</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Representation of a borrowed C string.</p>
|
|
|
<p>This type represents a borrowed reference to a nul-terminated
|
|
|
array of bytes. It can be constructed safely from a <code>&[<a href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html" title="primitive u8">u8</a>]</code>
|
|
|
slice, or unsafely from a raw <code>*const c_char</code>. It can then be
|
|
|
converted to a Rust <code>&<a href="https://doc.rust-lang.org/1.76.0/std/primitive.str.html" title="str">str</a></code> by performing UTF-8 validation, or
|
|
|
into an owned <a href="../../std/ffi/struct.CString.html"><code>CString</code></a>.</p>
|
|
|
<p><code>&CStr</code> is to <a href="../../std/ffi/struct.CString.html"><code>CString</code></a> as <code>&<a href="https://doc.rust-lang.org/1.76.0/std/primitive.str.html" title="str">str</a></code> is to <a href="../../std/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 does <strong>not</strong> have a guaranteed layout (the <code>repr(transparent)</code>
|
|
|
notwithstanding) and is not recommended to be placed in the signatures of FFI functions.
|
|
|
Instead, safe wrappers of FFI functions may leverage the unsafe <a href="struct.CStr.html#method.from_ptr" title="associated function rustix::ffi::CStr::from_ptr"><code>CStr::from_ptr</code></a> constructor
|
|
|
to provide a safe interface to other consumers.</p>
|
|
|
<h2 id="examples"><a href="#examples">Examples</a></h2>
|
|
|
<p>Inspecting a foreign C string:</p>
|
|
|
|
|
|
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CStr;
|
|
|
<span class="kw">use </span>std::os::raw::c_char;
|
|
|
|
|
|
<span class="kw">extern </span><span class="string">"C" </span>{ <span class="kw">fn </span>my_string() -> <span class="kw-2">*const </span>c_char; }
|
|
|
|
|
|
<span class="kw">unsafe </span>{
|
|
|
<span class="kw">let </span>slice = CStr::from_ptr(my_string());
|
|
|
<span class="macro">println!</span>(<span class="string">"string buffer size without nul terminator: {}"</span>, slice.to_bytes().len());
|
|
|
}</code></pre></div>
|
|
|
<p>Passing a Rust-originating C string:</p>
|
|
|
|
|
|
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::{CString, CStr};
|
|
|
<span class="kw">use </span>std::os::raw::c_char;
|
|
|
|
|
|
<span class="kw">fn </span>work(data: <span class="kw-2">&</span>CStr) {
|
|
|
<span class="kw">extern </span><span class="string">"C" </span>{ <span class="kw">fn </span>work_with(data: <span class="kw-2">*const </span>c_char); }
|
|
|
|
|
|
<span class="kw">unsafe </span>{ work_with(data.as_ptr()) }
|
|
|
}
|
|
|
|
|
|
<span class="kw">let </span>s = CString::new(<span class="string">"data data data data"</span>).expect(<span class="string">"CString::new failed"</span>);
|
|
|
work(<span class="kw-2">&</span>s);</code></pre></div>
|
|
|
<p>Converting a foreign C string into a Rust <code>String</code>:</p>
|
|
|
|
|
|
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CStr;
|
|
|
<span class="kw">use </span>std::os::raw::c_char;
|
|
|
|
|
|
<span class="kw">extern </span><span class="string">"C" </span>{ <span class="kw">fn </span>my_string() -> <span class="kw-2">*const </span>c_char; }
|
|
|
|
|
|
<span class="kw">fn </span>my_string_safe() -> String {
|
|
|
<span class="kw">let </span>cstr = <span class="kw">unsafe </span>{ CStr::from_ptr(my_string()) };
|
|
|
<span class="comment">// Get copy-on-write Cow<'_, str>, then guarantee a freshly-owned String allocation
|
|
|
</span>String::from_utf8_lossy(cstr.to_bytes()).to_string()
|
|
|
}
|
|
|
|
|
|
<span class="macro">println!</span>(<span class="string">"string: {}"</span>, my_string_safe());</code></pre></div>
|
|
|
</div></details><h2 id="implementations" class="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-CStr" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#195">source</a><a href="#impl-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from_ptr" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0, const unstable">1.0.0 (const: <a href="https://github.com/rust-lang/rust/issues/113219" title="Tracking issue for const_cstr_from_ptr">unstable</a>)</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#262">source</a></span><h4 class="code-header">pub unsafe fn <a href="#method.from_ptr" class="fn">from_ptr</a><'a>(ptr: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.pointer.html">*const </a><a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.i8.html">i8</a>) -> &'a <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h4></section></summary><div class="docblock"><p>Wraps a raw C string with a safe C string wrapper.</p>
|
|
|
<p>This function will wrap the provided <code>ptr</code> with a <code>CStr</code> wrapper, which
|
|
|
allows inspection and interoperation of non-owned C strings. The total
|
|
|
size of the terminated buffer must be smaller than <a href="https://doc.rust-lang.org/1.76.0/std/primitive.isize.html#associatedconstant.MAX" title="associated constant isize::MAX"><code>isize::MAX</code></a> <strong>bytes</strong>
|
|
|
in memory (a restriction from <a href="https://doc.rust-lang.org/1.76.0/core/slice/raw/fn.from_raw_parts.html" title="fn core::slice::raw::from_raw_parts"><code>slice::from_raw_parts</code></a>).</p>
|
|
|
<h5 id="safety"><a href="#safety">Safety</a></h5>
|
|
|
<ul>
|
|
|
<li>
|
|
|
<p>The memory pointed to by <code>ptr</code> must contain a valid nul terminator at the
|
|
|
end of the string.</p>
|
|
|
</li>
|
|
|
<li>
|
|
|
<p><code>ptr</code> must be <a href="https://doc.rust-lang.org/1.76.0/core/ptr/index.html#safety" title="mod core::ptr">valid</a> for reads of bytes up to and including the nul terminator.
|
|
|
This means in particular:</p>
|
|
|
<ul>
|
|
|
<li>The entire memory range of this <code>CStr</code> must be contained within a single allocated object!</li>
|
|
|
<li><code>ptr</code> must be non-null even for a zero-length cstr.</li>
|
|
|
</ul>
|
|
|
</li>
|
|
|
<li>
|
|
|
<p>The memory referenced by the returned <code>CStr</code> must not be mutated for
|
|
|
the duration of lifetime <code>'a</code>.</p>
|
|
|
</li>
|
|
|
<li>
|
|
|
<p>The nul terminator must be within <code>isize::MAX</code> from <code>ptr</code></p>
|
|
|
</li>
|
|
|
</ul>
|
|
|
<blockquote>
|
|
|
<p><strong>Note</strong>: This operation is intended to be a 0-cost cast but it is
|
|
|
currently implemented with an up-front calculation of the length of
|
|
|
the string. This is not guaranteed to always be the case.</p>
|
|
|
</blockquote>
|
|
|
<h5 id="caveat"><a href="#caveat">Caveat</a></h5>
|
|
|
<p>The lifetime for the returned slice is inferred from its usage. To prevent accidental misuse,
|
|
|
it’s suggested to tie the lifetime to whichever source lifetime is safe in the context,
|
|
|
such as by providing a helper function taking the lifetime of a host value for the slice,
|
|
|
or by explicit annotation.</p>
|
|
|
<h5 id="examples-1"><a href="#examples-1">Examples</a></h5>
|
|
|
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::{c_char, CStr};
|
|
|
|
|
|
<span class="kw">extern </span><span class="string">"C" </span>{
|
|
|
<span class="kw">fn </span>my_string() -> <span class="kw-2">*const </span>c_char;
|
|
|
}
|
|
|
|
|
|
<span class="kw">unsafe </span>{
|
|
|
<span class="kw">let </span>slice = CStr::from_ptr(my_string());
|
|
|
<span class="macro">println!</span>(<span class="string">"string returned: {}"</span>, slice.to_str().unwrap());
|
|
|
}</code></pre></div>
|
|
|
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#![feature(const_cstr_from_ptr)]
|
|
|
|
|
|
</span><span class="kw">use </span>std::ffi::{c_char, CStr};
|
|
|
|
|
|
<span class="kw">const </span>HELLO_PTR: <span class="kw-2">*const </span>c_char = {
|
|
|
<span class="kw">const </span>BYTES: <span class="kw-2">&</span>[u8] = <span class="string">b"Hello, world!\0"</span>;
|
|
|
BYTES.as_ptr().cast()
|
|
|
};
|
|
|
<span class="kw">const </span>HELLO: <span class="kw-2">&</span>CStr = <span class="kw">unsafe </span>{ CStr::from_ptr(HELLO_PTR) };</code></pre></div>
|
|
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.from_bytes_until_nul" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.69.0, const since 1.69.0">1.69.0 (const: 1.69.0)</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#307">source</a></span><h4 class="code-header">pub const fn <a href="#method.from_bytes_until_nul" class="fn">from_bytes_until_nul</a>(
|
|
|
bytes: &[<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>]
|
|
|
) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><&<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>, <a class="struct" href="https://doc.rust-lang.org/1.76.0/core/ffi/c_str/struct.FromBytesUntilNulError.html" title="struct core::ffi::c_str::FromBytesUntilNulError">FromBytesUntilNulError</a>></h4></section></summary><div class="docblock"><p>Creates a C string wrapper from a byte slice with any number of nuls.</p>
|
|
|
<p>This method will create a <code>CStr</code> from any byte slice that contains at
|
|
|
least one nul byte. Unlike with <a href="struct.CStr.html#method.from_bytes_with_nul" title="associated function rustix::ffi::CStr::from_bytes_with_nul"><code>CStr::from_bytes_with_nul</code></a>, the caller
|
|
|
does not need to know where the nul byte is located.</p>
|
|
|
<p>If the first byte is a nul character, this method will return an
|
|
|
empty <code>CStr</code>. If multiple nul characters are present, the <code>CStr</code> will
|
|
|
end at the first one.</p>
|
|
|
<p>If the slice only has a single nul byte at the end, this method is
|
|
|
equivalent to <a href="struct.CStr.html#method.from_bytes_with_nul" title="associated function rustix::ffi::CStr::from_bytes_with_nul"><code>CStr::from_bytes_with_nul</code></a>.</p>
|
|
|
<h5 id="examples-2"><a href="#examples-2">Examples</a></h5>
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CStr;
|
|
|
|
|
|
<span class="kw">let </span><span class="kw-2">mut </span>buffer = [<span class="number">0u8</span>; <span class="number">16</span>];
|
|
|
<span class="kw">unsafe </span>{
|
|
|
<span class="comment">// Here we might call an unsafe C function that writes a string
|
|
|
// into the buffer.
|
|
|
</span><span class="kw">let </span>buf_ptr = buffer.as_mut_ptr();
|
|
|
buf_ptr.write_bytes(<span class="string">b'A'</span>, <span class="number">8</span>);
|
|
|
}
|
|
|
<span class="comment">// Attempt to extract a C nul-terminated string from the buffer.
|
|
|
</span><span class="kw">let </span>c_str = CStr::from_bytes_until_nul(<span class="kw-2">&</span>buffer[..]).unwrap();
|
|
|
<span class="macro">assert_eq!</span>(c_str.to_str().unwrap(), <span class="string">"AAAAAAAA"</span>);</code></pre></div>
|
|
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.from_bytes_with_nul" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.10.0, const since 1.72.0">1.10.0 (const: 1.72.0)</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#360">source</a></span><h4 class="code-header">pub const fn <a href="#method.from_bytes_with_nul" class="fn">from_bytes_with_nul</a>(
|
|
|
bytes: &[<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>]
|
|
|
) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><&<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>, <a class="struct" href="struct.FromBytesWithNulError.html" title="struct rustix::ffi::FromBytesWithNulError">FromBytesWithNulError</a>></h4></section></summary><div class="docblock"><p>Creates a C string wrapper from a byte slice with exactly one nul
|
|
|
terminator.</p>
|
|
|
<p>This function will cast the provided <code>bytes</code> to a <code>CStr</code>
|
|
|
wrapper after ensuring that the byte slice is nul-terminated
|
|
|
and does not contain any interior nul bytes.</p>
|
|
|
<p>If the nul byte may not be at the end,
|
|
|
<a href="struct.CStr.html#method.from_bytes_until_nul" title="associated function rustix::ffi::CStr::from_bytes_until_nul"><code>CStr::from_bytes_until_nul</code></a> can be used instead.</p>
|
|
|
<h5 id="examples-3"><a href="#examples-3">Examples</a></h5>
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CStr;
|
|
|
|
|
|
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"hello\0"</span>);
|
|
|
<span class="macro">assert!</span>(cstr.is_ok());</code></pre></div>
|
|
|
<p>Creating a <code>CStr</code> without a trailing nul terminator is an error:</p>
|
|
|
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CStr;
|
|
|
|
|
|
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"hello"</span>);
|
|
|
<span class="macro">assert!</span>(cstr.is_err());</code></pre></div>
|
|
|
<p>Creating a <code>CStr</code> with an interior nul byte is an error:</p>
|
|
|
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CStr;
|
|
|
|
|
|
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"he\0llo\0"</span>);
|
|
|
<span class="macro">assert!</span>(cstr.is_err());</code></pre></div>
|
|
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.from_bytes_with_nul_unchecked" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.10.0, const since 1.59.0">1.10.0 (const: 1.59.0)</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#398">source</a></span><h4 class="code-header">pub const unsafe fn <a href="#method.from_bytes_with_nul_unchecked" class="fn">from_bytes_with_nul_unchecked</a>(bytes: &[<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>]) -> &<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h4></section></summary><div class="docblock"><p>Unsafely creates a C string wrapper from a byte slice.</p>
|
|
|
<p>This function will cast the provided <code>bytes</code> to a <code>CStr</code> wrapper without
|
|
|
performing any sanity checks.</p>
|
|
|
<h5 id="safety-1"><a href="#safety-1">Safety</a></h5>
|
|
|
<p>The provided slice <strong>must</strong> be nul-terminated and not contain any interior
|
|
|
nul bytes.</p>
|
|
|
<h5 id="examples-4"><a href="#examples-4">Examples</a></h5>
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::{CStr, CString};
|
|
|
|
|
|
<span class="kw">unsafe </span>{
|
|
|
<span class="kw">let </span>cstring = CString::new(<span class="string">"hello"</span>).expect(<span class="string">"CString::new failed"</span>);
|
|
|
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul_unchecked(cstring.to_bytes_with_nul());
|
|
|
<span class="macro">assert_eq!</span>(cstr, <span class="kw-2">&*</span>cstring);
|
|
|
}</code></pre></div>
|
|
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.as_ptr" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0, const since 1.32.0">1.0.0 (const: 1.32.0)</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#491">source</a></span><h4 class="code-header">pub const fn <a href="#method.as_ptr" class="fn">as_ptr</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.pointer.html">*const </a><a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.i8.html">i8</a></h4></section></summary><div class="docblock"><p>Returns the inner pointer to this C string.</p>
|
|
|
<p>The returned pointer will be valid for as long as <code>self</code> is, and points
|
|
|
to a contiguous region of memory terminated with a 0 byte to represent
|
|
|
the end of the string.</p>
|
|
|
<p>The type of the returned pointer is
|
|
|
<a href="https://doc.rust-lang.org/1.76.0/core/ffi/type.c_char.html" title="type core::ffi::c_char"><code>*const c_char</code></a>, and whether it’s
|
|
|
an alias for <code>*const i8</code> or <code>*const u8</code> is platform-specific.</p>
|
|
|
<p><strong>WARNING</strong></p>
|
|
|
<p>The returned pointer is read-only; writing to it (including passing it
|
|
|
to C code that writes to it) causes undefined behavior.</p>
|
|
|
<p>It is your responsibility to make sure that the underlying memory is not
|
|
|
freed too early. For example, the following code will cause undefined
|
|
|
behavior when <code>ptr</code> is used inside the <code>unsafe</code> block:</p>
|
|
|
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CString;
|
|
|
|
|
|
<span class="comment">// Do not do this:
|
|
|
</span><span class="kw">let </span>ptr = CString::new(<span class="string">"Hello"</span>).expect(<span class="string">"CString::new failed"</span>).as_ptr();
|
|
|
<span class="kw">unsafe </span>{
|
|
|
<span class="comment">// `ptr` is dangling
|
|
|
</span><span class="kw-2">*</span>ptr;
|
|
|
}</code></pre></div>
|
|
|
<p>This happens because the pointer returned by <code>as_ptr</code> does not carry any
|
|
|
lifetime information and the <code>CString</code> is deallocated immediately after
|
|
|
the <code>CString::new("Hello").expect("CString::new failed").as_ptr()</code>
|
|
|
expression is evaluated.
|
|
|
To fix the problem, bind the <code>CString</code> to a local variable:</p>
|
|
|
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CString;
|
|
|
|
|
|
<span class="kw">let </span>hello = CString::new(<span class="string">"Hello"</span>).expect(<span class="string">"CString::new failed"</span>);
|
|
|
<span class="kw">let </span>ptr = hello.as_ptr();
|
|
|
<span class="kw">unsafe </span>{
|
|
|
<span class="comment">// `ptr` is valid because `hello` is in scope
|
|
|
</span><span class="kw-2">*</span>ptr;
|
|
|
}</code></pre></div>
|
|
|
<p>This way, the lifetime of the <code>CString</code> in <code>hello</code> encompasses
|
|
|
the lifetime of <code>ptr</code> and the <code>unsafe</code> block.</p>
|
|
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.count_bytes" class="method"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/113219" title="Tracking issue for const_cstr_from_ptr">unstable</a></span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#519">source</a></span><h4 class="code-header">pub fn <a href="#method.count_bytes" class="fn">count_bytes</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span><span>This is a nightly-only experimental API. (<code>cstr_count_bytes</code>)</span></div></span></summary><div class="docblock"><p>Returns the length of <code>self</code>. Like C’s <code>strlen</code>, this does not include the nul terminator.</p>
|
|
|
<blockquote>
|
|
|
<p><strong>Note</strong>: This method is currently implemented as a constant-time
|
|
|
cast, but it is planned to alter its definition in the future to
|
|
|
perform the length calculation whenever this method is called.</p>
|
|
|
</blockquote>
|
|
|
<h5 id="examples-5"><a href="#examples-5">Examples</a></h5>
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#![feature(cstr_count_bytes)]
|
|
|
|
|
|
</span><span class="kw">use </span>std::ffi::CStr;
|
|
|
|
|
|
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"foo\0"</span>).unwrap();
|
|
|
<span class="macro">assert_eq!</span>(cstr.count_bytes(), <span class="number">3</span>);
|
|
|
|
|
|
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"\0"</span>).unwrap();
|
|
|
<span class="macro">assert_eq!</span>(cstr.count_bytes(), <span class="number">0</span>);</code></pre></div>
|
|
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.is_empty" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.71.0, const since 1.71.0">1.71.0 (const: 1.71.0)</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#544">source</a></span><h4 class="code-header">pub const fn <a href="#method.is_empty" class="fn">is_empty</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if <code>self.to_bytes()</code> has a length of 0.</p>
|
|
|
<h5 id="examples-6"><a href="#examples-6">Examples</a></h5>
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CStr;
|
|
|
|
|
|
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"foo\0"</span>)<span class="question-mark">?</span>;
|
|
|
<span class="macro">assert!</span>(!cstr.is_empty());
|
|
|
|
|
|
<span class="kw">let </span>empty_cstr = CStr::from_bytes_with_nul(<span class="string">b"\0"</span>)<span class="question-mark">?</span>;
|
|
|
<span class="macro">assert!</span>(empty_cstr.is_empty());</code></pre></div>
|
|
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.to_bytes" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0, const since 1.72.0">1.0.0 (const: 1.72.0)</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#573">source</a></span><h4 class="code-header">pub const fn <a href="#method.to_bytes" class="fn">to_bytes</a>(&self) -> &[<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>] <a href="#" class="tooltip" data-notable-ty="&[u8]">ⓘ</a></h4></section></summary><div class="docblock"><p>Converts this C string to a byte slice.</p>
|
|
|
<p>The returned slice will <strong>not</strong> contain the trailing nul terminator that this C
|
|
|
string has.</p>
|
|
|
<blockquote>
|
|
|
<p><strong>Note</strong>: This method is currently implemented as a constant-time
|
|
|
cast, but it is planned to alter its definition in the future to
|
|
|
perform the length calculation whenever this method is called.</p>
|
|
|
</blockquote>
|
|
|
<h5 id="examples-7"><a href="#examples-7">Examples</a></h5>
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CStr;
|
|
|
|
|
|
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"foo\0"</span>).expect(<span class="string">"CStr::from_bytes_with_nul failed"</span>);
|
|
|
<span class="macro">assert_eq!</span>(cstr.to_bytes(), <span class="string">b"foo"</span>);</code></pre></div>
|
|
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.to_bytes_with_nul" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0, const since 1.72.0">1.0.0 (const: 1.72.0)</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#602">source</a></span><h4 class="code-header">pub const fn <a href="#method.to_bytes_with_nul" class="fn">to_bytes_with_nul</a>(&self) -> &[<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>] <a href="#" class="tooltip" data-notable-ty="&[u8]">ⓘ</a></h4></section></summary><div class="docblock"><p>Converts this C string to a byte slice containing the trailing 0 byte.</p>
|
|
|
<p>This function is the equivalent of <a href="struct.CStr.html#method.to_bytes" title="method rustix::ffi::CStr::to_bytes"><code>CStr::to_bytes</code></a> except that it
|
|
|
will retain the trailing nul terminator instead of chopping it off.</p>
|
|
|
<blockquote>
|
|
|
<p><strong>Note</strong>: This method is currently implemented as a 0-cost cast, but
|
|
|
it is planned to alter its definition in the future to perform the
|
|
|
length calculation whenever this method is called.</p>
|
|
|
</blockquote>
|
|
|
<h5 id="examples-8"><a href="#examples-8">Examples</a></h5>
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CStr;
|
|
|
|
|
|
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"foo\0"</span>).expect(<span class="string">"CStr::from_bytes_with_nul failed"</span>);
|
|
|
<span class="macro">assert_eq!</span>(cstr.to_bytes_with_nul(), <span class="string">b"foo\0"</span>);</code></pre></div>
|
|
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.to_str" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.4.0, const since 1.72.0">1.4.0 (const: 1.72.0)</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#626">source</a></span><h4 class="code-header">pub const fn <a href="#method.to_str" class="fn">to_str</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><&<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.str.html">str</a>, <a class="struct" href="https://doc.rust-lang.org/1.76.0/core/str/error/struct.Utf8Error.html" title="struct core::str::error::Utf8Error">Utf8Error</a>></h4></section></summary><div class="docblock"><p>Yields a <code>&<a href="https://doc.rust-lang.org/1.76.0/std/primitive.str.html" title="str">str</a></code> slice if the <code>CStr</code> contains valid UTF-8.</p>
|
|
|
<p>If the contents of the <code>CStr</code> are valid UTF-8 data, this
|
|
|
function will return the corresponding <code>&<a href="https://doc.rust-lang.org/1.76.0/std/primitive.str.html" title="str">str</a></code> slice. Otherwise,
|
|
|
it will return an error with details of where UTF-8 validation failed.</p>
|
|
|
<h5 id="examples-9"><a href="#examples-9">Examples</a></h5>
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CStr;
|
|
|
|
|
|
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"foo\0"</span>).expect(<span class="string">"CStr::from_bytes_with_nul failed"</span>);
|
|
|
<span class="macro">assert_eq!</span>(cstr.to_str(), <span class="prelude-val">Ok</span>(<span class="string">"foo"</span>));</code></pre></div>
|
|
|
</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-CStr-1" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/alloc/ffi/c_str.rs.html#1051">source</a><a href="#impl-CStr-1" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.to_string_lossy" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.4.0">1.4.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/alloc/ffi/c_str.rs.html#1096">source</a></span><h4 class="code-header">pub fn <a href="#method.to_string_lossy" class="fn">to_string_lossy</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'_, <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.str.html">str</a>></h4></section></summary><div class="docblock"><p>Converts a <code>CStr</code> into a <code><a href="https://doc.rust-lang.org/1.76.0/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><<a href="https://doc.rust-lang.org/1.76.0/std/primitive.str.html" title="str">str</a>></code>.</p>
|
|
|
<p>If the contents of the <code>CStr</code> are valid UTF-8 data, this
|
|
|
function will return a <code><a href="https://doc.rust-lang.org/1.76.0/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a>::<a href="https://doc.rust-lang.org/1.76.0/alloc/borrow/enum.Cow.html#variant.Borrowed" title="variant alloc::borrow::Cow::Borrowed">Borrowed</a>(&<a href="https://doc.rust-lang.org/1.76.0/std/primitive.str.html" title="str">str</a>)</code>
|
|
|
with the corresponding <code>&<a href="https://doc.rust-lang.org/1.76.0/std/primitive.str.html" title="str">str</a></code> slice. Otherwise, it will
|
|
|
replace any invalid UTF-8 sequences with
|
|
|
<a href="https://doc.rust-lang.org/1.76.0/core/char/constant.REPLACEMENT_CHARACTER.html" title="std::char::REPLACEMENT_CHARACTER"><code>U+FFFD REPLACEMENT CHARACTER</code></a> and return a
|
|
|
<code><a href="https://doc.rust-lang.org/1.76.0/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a>::<a href="https://doc.rust-lang.org/1.76.0/alloc/borrow/enum.Cow.html#variant.Owned" title="variant alloc::borrow::Cow::Owned">Owned</a>(&<a href="https://doc.rust-lang.org/1.76.0/std/primitive.str.html" title="str">str</a>)</code> with the result.</p>
|
|
|
<h5 id="examples-10"><a href="#examples-10">Examples</a></h5>
|
|
|
<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"><code><span class="kw">use </span>std::borrow::Cow;
|
|
|
<span class="kw">use </span>std::ffi::CStr;
|
|
|
|
|
|
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"Hello World\0"</span>)
|
|
|
.expect(<span class="string">"CStr::from_bytes_with_nul failed"</span>);
|
|
|
<span class="macro">assert_eq!</span>(cstr.to_string_lossy(), Cow::Borrowed(<span class="string">"Hello World"</span>));</code></pre></div>
|
|
|
<p>Calling <code>to_string_lossy</code> on a <code>CStr</code> containing invalid UTF-8:</p>
|
|
|
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::borrow::Cow;
|
|
|
<span class="kw">use </span>std::ffi::CStr;
|
|
|
|
|
|
<span class="kw">let </span>cstr = CStr::from_bytes_with_nul(<span class="string">b"Hello \xF0\x90\x80World\0"</span>)
|
|
|
.expect(<span class="string">"CStr::from_bytes_with_nul failed"</span>);
|
|
|
<span class="macro">assert_eq!</span>(
|
|
|
cstr.to_string_lossy(),
|
|
|
Cow::Owned(String::from(<span class="string">"Hello <20>World"</span>)) <span class="kw">as </span>Cow<<span class="lifetime">'_</span>, str>
|
|
|
);</code></pre></div>
|
|
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.into_c_string" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.20.0">1.20.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/alloc/ffi/c_str.rs.html#1114">source</a></span><h4 class="code-header">pub fn <a href="#method.into_c_string" class="fn">into_c_string</a>(self: <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>>) -> <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h4></section></summary><div class="docblock"><p>Converts a <code><a href="https://doc.rust-lang.org/1.76.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><<a href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>></code> into a <a href="struct.CString.html" title="struct rustix::ffi::CString"><code>CString</code></a> without copying or allocating.</p>
|
|
|
<h5 id="examples-11"><a href="#examples-11">Examples</a></h5>
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::ffi::CString;
|
|
|
|
|
|
<span class="kw">let </span>c_string = CString::new(<span class="string">b"foo"</span>.to_vec()).expect(<span class="string">"CString::new failed"</span>);
|
|
|
<span class="kw">let </span>boxed = c_string.into_boxed_c_str();
|
|
|
<span class="macro">assert_eq!</span>(boxed.into_c_string(), CString::new(<span class="string">"foo"</span>).expect(<span class="string">"CString::new failed"</span>));</code></pre></div>
|
|
|
</div></details></div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-AsRef%3CCStr%3E-for-CStr" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.7.0">1.7.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#683">source</a></span><a href="#impl-AsRef%3CCStr%3E-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>> for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.as_ref" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#685">source</a><a href="#method.as_ref" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.AsRef.html#tymethod.as_ref" class="fn">as_ref</a>(&self) -> &<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h4></section></summary><div class='docblock'>Converts this type into a shared reference of the (usually inferred) input type.</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-AsRef%3CCStr%3E-for-CString" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.7.0">1.7.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/alloc/ffi/c_str.rs.html#1043">source</a></span><a href="#impl-AsRef%3CCStr%3E-for-CString" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>> for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.as_ref-1" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/alloc/ffi/c_str.rs.html#1045">source</a><a href="#method.as_ref-1" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.AsRef.html#tymethod.as_ref" class="fn">as_ref</a>(&self) -> &<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h4></section></summary><div class='docblock'>Converts this type into a shared reference of the (usually inferred) input type.</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Borrow%3CCStr%3E-for-CString" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.3.0">1.3.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/alloc/ffi/c_str.rs.html#746">source</a></span><a href="#impl-Borrow%3CCStr%3E-for-CString" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>> for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/alloc/ffi/c_str.rs.html#748">source</a><a href="#method.borrow" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.Borrow.html#tymethod.borrow" class="fn">borrow</a>(&self) -> &<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Debug-for-CStr" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.3.0">1.3.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#167">source</a></span><a href="#impl-Debug-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#168">source</a><a href="#method.fmt" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/fmt/trait.Debug.html#tymethod.fmt" class="fn">fmt</a>(&self, f: &mut <a class="struct" href="https://doc.rust-lang.org/1.76.0/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a><'_>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>, <a class="struct" href="https://doc.rust-lang.org/1.76.0/core/fmt/struct.Error.html" title="struct core::fmt::Error">Error</a>></h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/1.76.0/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Default-for-%26CStr" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.10.0">1.10.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#174">source</a></span><a href="#impl-Default-for-%26CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/default/trait.Default.html" title="trait core::default::Default">Default</a> for &<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.default" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#176">source</a><a href="#method.default" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/default/trait.Default.html#tymethod.default" class="fn">default</a>() -> &<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h4></section></summary><div class='docblock'>Returns the “default value” for a type. <a href="https://doc.rust-lang.org/1.76.0/core/default/trait.Default.html#tymethod.default">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-From%3C%26CStr%3E-for-CString" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.7.0">1.7.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/alloc/ffi/c_str.rs.html#1026">source</a></span><a href="#impl-From%3C%26CStr%3E-for-CString" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><&<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>> for <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/alloc/ffi/c_str.rs.html#1027">source</a><a href="#method.from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.From.html#tymethod.from" class="fn">from</a>(s: &<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>) -> <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h4></section></summary><div class='docblock'>Converts to this type from the input type.</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Hash-for-CStr" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#81">source</a><a href="#impl-Hash-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.hash" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#81">source</a><a href="#method.hash" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html#tymethod.hash" class="fn">hash</a><__H>(&self, state: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&mut __H</a>)<div class="where">where
|
|
|
__H: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hasher.html" title="trait core::hash::Hasher">Hasher</a>,</div></h4></section></summary><div class='docblock'>Feeds this value into the given <a href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hasher.html" title="trait core::hash::Hasher"><code>Hasher</code></a>. <a href="https://doc.rust-lang.org/1.76.0/core/hash/trait.Hash.html#tymethod.hash">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Index%3CRangeFrom%3Cusize%3E%3E-for-CStr" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.47.0">1.47.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#660">source</a></span><a href="#impl-Index%3CRangeFrom%3Cusize%3E%3E-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/index/trait.Index.html" title="trait core::ops::index::Index">Index</a><<a class="struct" href="https://doc.rust-lang.org/1.76.0/core/ops/range/struct.RangeFrom.html" title="struct core::ops::range::RangeFrom">RangeFrom</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>>> for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Output" class="associatedtype trait-impl"><a href="#associatedtype.Output" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.76.0/core/ops/index/trait.Index.html#associatedtype.Output" class="associatedtype">Output</a> = <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h4></section></summary><div class='docblock'>The returned type after indexing.</div></details><details class="toggle method-toggle" open><summary><section id="method.index" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#664">source</a><a href="#method.index" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/ops/index/trait.Index.html#tymethod.index" class="fn">index</a>(&self, index: <a class="struct" href="https://doc.rust-lang.org/1.76.0/core/ops/range/struct.RangeFrom.html" title="struct core::ops::range::RangeFrom">RangeFrom</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>>) -> &<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h4></section></summary><div class='docblock'>Performs the indexing (<code>container[index]</code>) operation. <a href="https://doc.rust-lang.org/1.76.0/core/ops/index/trait.Index.html#tymethod.index">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Ord-for-CStr" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#652">source</a></span><a href="#impl-Ord-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a> for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.cmp" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#654">source</a><a href="#method.cmp" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html#tymethod.cmp" class="fn">cmp</a>(&self, other: &<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a></h4></section></summary><div class='docblock'>This method returns an <a href="https://doc.rust-lang.org/1.76.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering"><code>Ordering</code></a> between <code>self</code> and <code>other</code>. <a href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Ord.html#tymethod.cmp">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-PartialEq-for-CStr" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#636">source</a></span><a href="#impl-PartialEq-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a> for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.eq" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#638">source</a><a href="#method.eq" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialEq.html#tymethod.eq" class="fn">eq</a>(&self, other: &<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used
|
|
|
by <code>==</code>.</div></details><details class="toggle method-toggle" open><summary><section id="method.ne" class="method trait-impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/cmp.rs.html#242">source</a></span><a href="#method.ne" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialEq.html#method.ne" class="fn">ne</a>(&self, other: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&Rhs</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>This method tests for <code>!=</code>. The default implementation is almost always
|
|
|
sufficient, and should not be overridden without very good reason.</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-PartialOrd-for-CStr" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#645">source</a></span><a href="#impl-PartialOrd-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a> for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.partial_cmp" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#647">source</a><a href="#method.partial_cmp" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html#tymethod.partial_cmp" class="fn">partial_cmp</a>(&self, other: &<a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="enum" href="https://doc.rust-lang.org/1.76.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>></h4></section></summary><div class='docblock'>This method returns an ordering between <code>self</code> and <code>other</code> values if one exists. <a href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html#tymethod.partial_cmp">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.lt" class="method trait-impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/cmp.rs.html#1125">source</a></span><a href="#method.lt" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html#method.lt" class="fn">lt</a>(&self, other: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&Rhs</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>This method tests less than (for <code>self</code> and <code>other</code>) and is used by the <code><</code> operator. <a href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html#method.lt">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.le" class="method trait-impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/cmp.rs.html#1142">source</a></span><a href="#method.le" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html#method.le" class="fn">le</a>(&self, other: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&Rhs</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>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="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html#method.le">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.gt" class="method trait-impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/cmp.rs.html#1158">source</a></span><a href="#method.gt" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html#method.gt" class="fn">gt</a>(&self, other: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&Rhs</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>This method tests greater than (for <code>self</code> and <code>other</code>) and is used by the <code>></code> operator. <a href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html#method.gt">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.ge" class="method trait-impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/cmp.rs.html#1175">source</a></span><a href="#method.ge" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html#method.ge" class="fn">ge</a>(&self, other: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&Rhs</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>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="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html#method.ge">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-ToOwned-for-CStr" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.3.0">1.3.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/alloc/ffi/c_str.rs.html#1011">source</a></span><a href="#impl-ToOwned-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/alloc/borrow/trait.ToOwned.html" title="trait alloc::borrow::ToOwned">ToOwned</a> for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Owned" class="associatedtype trait-impl"><a href="#associatedtype.Owned" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.76.0/alloc/borrow/trait.ToOwned.html#associatedtype.Owned" class="associatedtype">Owned</a> = <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h4></section></summary><div class='docblock'>The resulting type after obtaining ownership.</div></details><details class="toggle method-toggle" open><summary><section id="method.to_owned" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/alloc/ffi/c_str.rs.html#1014">source</a><a href="#method.to_owned" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/alloc/borrow/trait.ToOwned.html#tymethod.to_owned" class="fn">to_owned</a>(&self) -> <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a></h4></section></summary><div class='docblock'>Creates owned data from borrowed data, usually by cloning. <a href="https://doc.rust-lang.org/1.76.0/alloc/borrow/trait.ToOwned.html#tymethod.to_owned">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.clone_into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/alloc/ffi/c_str.rs.html#1018">source</a><a href="#method.clone_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/alloc/borrow/trait.ToOwned.html#method.clone_into" class="fn">clone_into</a>(&self, target: &mut <a class="struct" href="struct.CString.html" title="struct rustix::ffi::CString">CString</a>)</h4></section></summary><div class='docblock'>Uses borrowed data to replace owned data, usually by cloning. <a href="https://doc.rust-lang.org/1.76.0/alloc/borrow/trait.ToOwned.html#method.clone_into">Read more</a></div></details></div></details><section id="impl-Eq-for-CStr" class="impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.76.0/src/core/ffi/c_str.rs.html#643">source</a></span><a href="#impl-Eq-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section></div><h2 id="synthetic-implementations" class="section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor">§</a></h2><div id="synthetic-implementations-list"><section id="impl-RefUnwindSafe-for-CStr" class="impl"><a href="#impl-RefUnwindSafe-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section><section id="impl-Send-for-CStr" class="impl"><a href="#impl-Send-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section><section id="impl-Sized-for-CStr" class="impl"><a href="#impl-Sized-for-CStr" class="anchor">§</a><h3 class="code-header">impl !<a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section><section id="impl-Sync-for-CStr" class="impl"><a href="#impl-Sync-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section><section id="impl-Unpin-for-CStr" class="impl"><a href="#impl-Unpin-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section><section id="impl-UnwindSafe-for-CStr" class="impl"><a href="#impl-UnwindSafe-for-CStr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.CStr.html" title="struct rustix::ffi::CStr">CStr</a></h3></section></div><h2 id="blanket-implementations" class="section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor">§</a></h2><div id="blanket-implementations-list"><details class="toggle implementors-toggle"><summary><section id="impl-Any-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/any.rs.html#140">source</a><a href="#impl-Any-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T<div class="where">where
|
|
|
T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/any.rs.html#141">source</a><a href="#method.type_id" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/any/trait.Any.html#tymethod.type_id" class="fn">type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/1.76.0/core/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/borrow.rs.html#208">source</a><a href="#impl-Borrow%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><T> for T<div class="where">where
|
|
|
T: ?<a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow-1" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/borrow.rs.html#210">source</a><a href="#method.borrow-1" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.Borrow.html#tymethod.borrow" class="fn">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&T</a></h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/borrow.rs.html#216">source</a><a href="#impl-BorrowMut%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><T> for T<div class="where">where
|
|
|
T: ?<a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/borrow.rs.html#217">source</a><a href="#method.borrow_mut" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fn">borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&mut T</a></h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></div></details></div></details></div><script type="text/json" id="notable-traits-data">{"&[u8]":"<h3>Notable traits for <code>&[<a class=\"primitive\" href=\"https://doc.rust-lang.org/1.76.0/std/primitive.u8.html\">u8</a>]</code></h3><pre><code><div class=\"where\">impl <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/std/io/trait.Read.html\" title=\"trait std::io::Read\">Read</a> for &[<a class=\"primitive\" href=\"https://doc.rust-lang.org/1.76.0/std/primitive.u8.html\">u8</a>]</div>"}</script></section></div></main></body></html> |