mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-28 12:23:36 +04:00
952 lines
218 KiB
HTML
952 lines
218 KiB
HTML
<!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="All of app’s name"><meta name="keywords" content="rust, rustlang, rust-lang, APP_NAMES"><title>APP_NAMES in os::loader - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled><link rel="stylesheet" type="text/css" href="../../dark.css" disabled><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script src="../../crates.js"></script><script defer src="../../main.js"></script>
|
||
<noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../favicon.svg"></head><body class="rustdoc struct"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="sidebar-logo" href="../../os/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div>
|
||
</a><h2 class="location"></h2>
|
||
</nav>
|
||
<nav class="sidebar"><a class="sidebar-logo" href="../../os/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div>
|
||
</a><h2 class="location"><a href="#">APP_NAMES</a></h2><div class="sidebar-elems"><section><div class="block"><h3 class="sidebar-title"><a href="#fields">Fields</a></h3><ul><li><a href="#structfield.__private_field">__private_field</a></li></ul></div><div class="block"><h3 class="sidebar-title"><a href="#deref-methods-Vec%3C%26%27static%20str%3E">Methods from Deref<Target=Vec<&'static str>></a></h3><ul><li><a href="#method.allocator">allocator</a></li><li><a href="#method.as_ptr">as_ptr</a></li><li><a href="#method.as_slice">as_slice</a></li><li><a href="#method.capacity">capacity</a></li><li><a href="#method.is_empty">is_empty</a></li><li><a href="#method.len">len</a></li></ul></div><div class="block"><h3 class="sidebar-title"><a href="#deref-methods-%5BT%5D">Methods from Deref<Target=[T]></a></h3><ul><li><a href="#method.align_to">align_to</a></li><li><a href="#method.array_chunks">array_chunks</a></li><li><a href="#method.array_windows">array_windows</a></li><li><a href="#method.as_chunks">as_chunks</a></li><li><a href="#method.as_chunks_unchecked">as_chunks_unchecked</a></li><li><a href="#method.as_ptr">as_ptr</a></li><li><a href="#method.as_ptr_range">as_ptr_range</a></li><li><a href="#method.as_rchunks">as_rchunks</a></li><li><a href="#method.as_simd">as_simd</a></li><li><a href="#method.binary_search">binary_search</a></li><li><a href="#method.binary_search_by">binary_search_by</a></li><li><a href="#method.binary_search_by_key">binary_search_by_key</a></li><li><a href="#method.chunks">chunks</a></li><li><a href="#method.chunks_exact">chunks_exact</a></li><li><a href="#method.concat">concat</a></li><li><a href="#method.connect">connect</a></li><li><a href="#method.contains">contains</a></li><li><a href="#method.ends_with">ends_with</a></li><li><a href="#method.eq_ignore_ascii_case">eq_ignore_ascii_case</a></li><li><a href="#method.escape_ascii">escape_ascii</a></li><li><a href="#method.first">first</a></li><li><a href="#method.flatten">flatten</a></li><li><a href="#method.get">get</a></li><li><a href="#method.get_unchecked">get_unchecked</a></li><li><a href="#method.group_by">group_by</a></li><li><a href="#method.is_ascii">is_ascii</a></li><li><a href="#method.is_empty">is_empty</a></li><li><a href="#method.is_sorted">is_sorted</a></li><li><a href="#method.is_sorted_by">is_sorted_by</a></li><li><a href="#method.is_sorted_by_key">is_sorted_by_key</a></li><li><a href="#method.iter">iter</a></li><li><a href="#method.join">join</a></li><li><a href="#method.last">last</a></li><li><a href="#method.len">len</a></li><li><a href="#method.partition_point">partition_point</a></li><li><a href="#method.rchunks">rchunks</a></li><li><a href="#method.rchunks_exact">rchunks_exact</a></li><li><a href="#method.repeat">repeat</a></li><li><a href="#method.rsplit">rsplit</a></li><li><a href="#method.rsplit_array_ref">rsplit_array_ref</a></li><li><a href="#method.rsplitn">rsplitn</a></li><li><a href="#method.split">split</a></li><li><a href="#method.split_array_ref">split_array_ref</a></li><li><a href="#method.split_at">split_at</a></li><li><a href="#method.split_at_unchecked">split_at_unchecked</a></li><li><a href="#method.split_first">split_first</a></li><li><a href="#method.split_inclusive">split_inclusive</a></li><li><a href="#method.split_last">split_last</a></li><li><a href="#method.splitn">splitn</a></li><li><a href="#method.starts_with">starts_with</a></li><li><a href="#method.strip_prefix">strip_prefix</a></li><li><a href="#method.strip_suffix">strip_suffix</a></li><li><a href="#method.to_ascii_lowercase">to_ascii_lowercase</a></li><li><a href="#method.to_ascii_uppercase">to_ascii_uppercase</a></li><li><a href="#method.to_vec">to_vec</a></li><li><a href="#method.to_vec_in">to_vec_in</a></li><li><a href="#method.trim_ascii">trim_ascii</a></li><li><a href="#method.trim_ascii_end">trim_ascii_end</a></li><li><a href="#method.trim_ascii_start">trim_ascii_start</a></li><li><a href="#method.windows">windows</a></li></ul></div><div class="block"><h3 class="sidebar-title"><a href="#trait-implementations">Trait Implementations</a></h3><ul><li><a href="#impl-Deref">Deref</a></li><li><a href="#impl-LazyStatic">LazyStatic</a></li></ul></div><div class="block"><h3 class="sidebar-title"><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul><li><a href="#impl-RefUnwindSafe">RefUnwindSafe</a></li><li><a href="#impl-Send">Send</a></li><li><a href="#impl-Sync">Sync</a></li><li><a href="#impl-Unpin">Unpin</a></li><li><a href="#impl-UnwindSafe">UnwindSafe</a></li></ul></div><div class="block"><h3 class="sidebar-title"><a href="#blanket-implementations">Blanket Implementations</a></h3><ul><li><a href="#impl-Any">Any</a></li><li><a href="#impl-Borrow%3CT%3E">Borrow<T></a></li><li><a href="#impl-BorrowMut%3CT%3E">BorrowMut<T></a></li><li><a href="#impl-From%3CT%3E">From<T></a></li><li><a href="#impl-Into%3CU%3E">Into<U></a></li><li><a href="#impl-TryFrom%3CU%3E">TryFrom<U></a></li><li><a href="#impl-TryInto%3CU%3E">TryInto<U></a></li></ul></div></section><h2 class="location"><a href="index.html">In os::loader</a></h2><div id="sidebar-vars" data-name="APP_NAMES" data-ty="struct" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../os/index.html"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></a><nav class="sub"><div class="theme-picker hidden"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"><img width="22" height="22" alt="Pick another theme!" src="../../brush.svg"></button><div id="theme-choices" role="menu"></div></div><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><button type="button" id="help-button" title="help">?</button><a id="settings-menu" href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></form></nav></div><section id="main-content" class="content"><div class="main-heading">
|
||
<h1 class="fqn"><span class="in-band">Struct <a href="../index.html">os</a>::<wbr><a href="index.html">loader</a>::<wbr><a class="struct" href="#">APP_NAMES</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../../src/os/loader.rs.html#30-53">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><div class="docblock item-decl"><pre class="rust struct"><code>struct APP_NAMES {
|
||
__private_field: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.unit.html">()</a>,
|
||
}</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>All of app’s name</p>
|
||
</div></details><h2 id="fields" class="fields small-section-header">Fields<a href="#fields" class="anchor"></a></h2><span id="structfield.__private_field" class="structfield small-section-header"><a href="#structfield.__private_field" class="anchor field"></a><code>__private_field: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.unit.html">()</a></code></span><h2 id="deref-methods-Vec%3C%26%27static%20str%3E" class="small-section-header"><span>Methods from <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a><Target = <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><&'static <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.str.html">str</a>>></span><a href="#deref-methods-Vec%3C%26%27static%20str%3E" class="anchor"></a></h2><div id="deref-methods-Vec%3C%26%27static%20str%3E-1"><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.capacity" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/alloc/vec/mod.rs.html#789">source</a></span><a href="#method.capacity" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.capacity" class="fnname">capacity</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Returns the number of elements the vector can hold without
|
||
reallocating.</p>
|
||
<h5 id="examples"><a href="#examples">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">vec</span>: <span class="ident">Vec</span><span class="op"><</span><span class="ident">i32</span><span class="op">></span> <span class="op">=</span> <span class="ident">Vec::with_capacity</span>(<span class="number">10</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">vec</span>.<span class="ident">capacity</span>(), <span class="number">10</span>);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_slice" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.7.0">1.7.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/alloc/vec/mod.rs.html#1087">source</a></span><a href="#method.as_slice" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.as_slice" class="fnname">as_slice</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[T]</a></h4></section></summary><div class="docblock"><p>Extracts a slice containing the entire vector.</p>
|
||
<p>Equivalent to <code>&s[..]</code>.</p>
|
||
<h5 id="examples-1"><a href="#examples-1">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::io</span>::{<span class="self">self</span>, <span class="ident">Write</span>};
|
||
<span class="kw">let</span> <span class="ident">buffer</span> <span class="op">=</span> <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">8</span>];
|
||
<span class="ident">io::sink</span>().<span class="ident">write</span>(<span class="ident">buffer</span>.<span class="ident">as_slice</span>()).<span class="ident">unwrap</span>();</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_ptr" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.37.0">1.37.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/alloc/vec/mod.rs.html#1135">source</a></span><a href="#method.as_ptr" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.as_ptr" class="fnname">as_ptr</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.pointer.html">*const T</a></h4></section></summary><div class="docblock"><p>Returns a raw pointer to the vector’s buffer.</p>
|
||
<p>The caller must ensure that the vector outlives the pointer this
|
||
function returns, or else it will end up pointing to garbage.
|
||
Modifying the vector may cause its buffer to be reallocated,
|
||
which would also make any pointers to it invalid.</p>
|
||
<p>The caller must also ensure that the memory the pointer (non-transitively) points to
|
||
is never written to (except inside an <code>UnsafeCell</code>) using this pointer or any pointer
|
||
derived from it. If you need to mutate the contents of the slice, use <a href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html#method.as_mut_ptr"><code>as_mut_ptr</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">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">4</span>];
|
||
<span class="kw">let</span> <span class="ident">x_ptr</span> <span class="op">=</span> <span class="ident">x</span>.<span class="ident">as_ptr</span>();
|
||
|
||
<span class="kw">unsafe</span> {
|
||
<span class="kw">for</span> <span class="ident">i</span> <span class="kw">in</span> <span class="number">0</span>..<span class="ident">x</span>.<span class="ident">len</span>() {
|
||
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span><span class="ident">x_ptr</span>.<span class="ident">add</span>(<span class="ident">i</span>), <span class="number">1</span> <span class="op"><</span><span class="op"><</span> <span class="ident">i</span>);
|
||
}
|
||
}</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.allocator" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/alloc/vec/mod.rs.html#1184">source</a></span><a href="#method.allocator" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.allocator" class="fnname">allocator</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>A</h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>allocator_api</code>)</div></span></summary><div class="docblock"><p>Returns a reference to the underlying allocator.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.len" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/alloc/vec/mod.rs.html#1898">source</a></span><a href="#method.len" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.len" class="fnname">len</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Returns the number of elements in the vector, also referred to
|
||
as its ‘length’.</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">let</span> <span class="ident">a</span> <span class="op">=</span> <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
<span class="macro">assert_eq!</span>(<span class="ident">a</span>.<span class="ident">len</span>(), <span class="number">3</span>);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.is_empty" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/alloc/vec/mod.rs.html#1914">source</a></span><a href="#method.is_empty" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.is_empty" class="fnname">is_empty</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if the vector contains no elements.</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">let</span> <span class="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> <span class="ident">Vec::new</span>();
|
||
<span class="macro">assert!</span>(<span class="ident">v</span>.<span class="ident">is_empty</span>());
|
||
|
||
<span class="ident">v</span>.<span class="ident">push</span>(<span class="number">1</span>);
|
||
<span class="macro">assert!</span>(<span class="op">!</span><span class="ident">v</span>.<span class="ident">is_empty</span>());</code></pre></div>
|
||
</div></details></div></div><h2 id="deref-methods-%5BT%5D" class="small-section-header"><span>Methods from <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a><Target = <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">]</a>></span><a href="#deref-methods-%5BT%5D" class="anchor"></a></h2><div id="deref-methods-%5BT%5D-1"><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.flatten" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#4026">source</a></span><a href="#method.flatten" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.flatten" class="fnname">flatten</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[T]</a></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_flatten</code>)</div></span></summary><div class="docblock"><p>Takes a <code>&[[T; N]]</code>, and flattens it to a <code>&[T]</code>.</p>
|
||
<h5 id="panics"><a href="#panics">Panics</a></h5>
|
||
<p>This panics if the length of the resulting slice would overflow a <code>usize</code>.</p>
|
||
<p>This is only possible when flattening a slice of arrays of zero-sized
|
||
types, and thus tends to be irrelevant in practice. If
|
||
<code>size_of::<T>() > 0</code>, this will never panic.</p>
|
||
<h5 id="examples-5"><a href="#examples-5">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">slice_flatten</span>)]</span>
|
||
|
||
<span class="macro">assert_eq!</span>([[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>], [<span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]].<span class="ident">flatten</span>(), <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]);
|
||
|
||
<span class="macro">assert_eq!</span>(
|
||
[[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>], [<span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]].<span class="ident">flatten</span>(),
|
||
[[<span class="number">1</span>, <span class="number">2</span>], [<span class="number">3</span>, <span class="number">4</span>], [<span class="number">5</span>, <span class="number">6</span>]].<span class="ident">flatten</span>(),
|
||
);
|
||
|
||
<span class="kw">let</span> <span class="ident">slice_of_empty_arrays</span>: <span class="kw-2">&</span>[[<span class="ident">i32</span>; <span class="number">0</span>]] <span class="op">=</span> <span class="kw-2">&</span>[[], [], [], [], []];
|
||
<span class="macro">assert!</span>(<span class="ident">slice_of_empty_arrays</span>.<span class="ident">flatten</span>().<span class="ident">is_empty</span>());
|
||
|
||
<span class="kw">let</span> <span class="ident">empty_slice_of_arrays</span>: <span class="kw-2">&</span>[[<span class="ident">u32</span>; <span class="number">10</span>]] <span class="op">=</span> <span class="kw-2">&</span>[];
|
||
<span class="macro">assert!</span>(<span class="ident">empty_slice_of_arrays</span>.<span class="ident">flatten</span>().<span class="ident">is_empty</span>());</code></pre></div>
|
||
</div></details></div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.is_ascii" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.23.0">1.23.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/ascii.rs.html#15">source</a></span><a href="#method.is_ascii" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.is_ascii" class="fnname">is_ascii</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Checks if all bytes in this slice are within the ASCII range.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.eq_ignore_ascii_case" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.23.0">1.23.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/ascii.rs.html#26">source</a></span><a href="#method.eq_ignore_ascii_case" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.eq_ignore_ascii_case" class="fnname">eq_ignore_ascii_case</a>(&self, other: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">]</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Checks that two slices are an ASCII case-insensitive match.</p>
|
||
<p>Same as <code>to_ascii_lowercase(a) == to_ascii_lowercase(b)</code>,
|
||
but without allocating and copying temporaries.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.escape_ascii" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.60.0">1.60.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/ascii.rs.html#78">source</a></span><a href="#method.escape_ascii" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.escape_ascii" class="fnname">escape_ascii</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/slice/ascii/struct.EscapeAscii.html" title="struct core::slice::ascii::EscapeAscii">EscapeAscii</a><'_></h4></section></summary><div class="docblock"><p>Returns an iterator that produces an escaped version of this slice,
|
||
treating it as an ASCII string.</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">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="string">b"0\t\r\n'\"\\\x9d"</span>;
|
||
<span class="kw">let</span> <span class="ident">escaped</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">escape_ascii</span>().<span class="ident">to_string</span>();
|
||
<span class="macro">assert_eq!</span>(<span class="ident">escaped</span>, <span class="string">"0\\t\\r\\n\\'\\\"\\\\\\x9d"</span>);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.trim_ascii_start" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/ascii.rs.html#97">source</a></span><a href="#method.trim_ascii_start" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.trim_ascii_start" class="fnname">trim_ascii_start</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">]</a></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>byte_slice_trim_ascii</code>)</div></span></summary><div class="docblock"><p>Returns a byte slice with leading ASCII whitespace bytes removed.</p>
|
||
<p>‘Whitespace’ refers to the definition used by
|
||
<code>u8::is_ascii_whitespace</code>.</p>
|
||
<h5 id="examples-7"><a href="#examples-7">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">byte_slice_trim_ascii</span>)]</span>
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="string">b" \t hello world\n"</span>.<span class="ident">trim_ascii_start</span>(), <span class="string">b"hello world\n"</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="string">b" "</span>.<span class="ident">trim_ascii_start</span>(), <span class="string">b""</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="string">b""</span>.<span class="ident">trim_ascii_start</span>(), <span class="string">b""</span>);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.trim_ascii_end" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/ascii.rs.html#126">source</a></span><a href="#method.trim_ascii_end" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.trim_ascii_end" class="fnname">trim_ascii_end</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">]</a></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>byte_slice_trim_ascii</code>)</div></span></summary><div class="docblock"><p>Returns a byte slice with trailing ASCII whitespace bytes removed.</p>
|
||
<p>‘Whitespace’ refers to the definition used by
|
||
<code>u8::is_ascii_whitespace</code>.</p>
|
||
<h5 id="examples-8"><a href="#examples-8">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">byte_slice_trim_ascii</span>)]</span>
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="string">b"\r hello world\n "</span>.<span class="ident">trim_ascii_end</span>(), <span class="string">b"\r hello world"</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="string">b" "</span>.<span class="ident">trim_ascii_end</span>(), <span class="string">b""</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="string">b""</span>.<span class="ident">trim_ascii_end</span>(), <span class="string">b""</span>);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.trim_ascii" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/ascii.rs.html#156">source</a></span><a href="#method.trim_ascii" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.trim_ascii" class="fnname">trim_ascii</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">]</a></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>byte_slice_trim_ascii</code>)</div></span></summary><div class="docblock"><p>Returns a byte slice with leading and trailing ASCII whitespace bytes
|
||
removed.</p>
|
||
<p>‘Whitespace’ refers to the definition used by
|
||
<code>u8::is_ascii_whitespace</code>.</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="attribute">#![<span class="ident">feature</span>(<span class="ident">byte_slice_trim_ascii</span>)]</span>
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="string">b"\r hello world\n "</span>.<span class="ident">trim_ascii</span>(), <span class="string">b"hello world"</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="string">b" "</span>.<span class="ident">trim_ascii</span>(), <span class="string">b""</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="string">b""</span>.<span class="ident">trim_ascii</span>(), <span class="string">b""</span>);</code></pre></div>
|
||
</div></details></div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.len-1" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#129">source</a></span><a href="#method.len-1" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.len-1" class="fnname">len</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Returns the number of elements in the slice.</p>
|
||
<h5 id="examples-10"><a href="#examples-10">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
<span class="macro">assert_eq!</span>(<span class="ident">a</span>.<span class="ident">len</span>(), <span class="number">3</span>);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.is_empty-1" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#152">source</a></span><a href="#method.is_empty-1" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.is_empty-1" class="fnname">is_empty</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if the slice has a length of 0.</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">let</span> <span class="ident">a</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
<span class="macro">assert!</span>(<span class="op">!</span><span class="ident">a</span>.<span class="ident">is_empty</span>());</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.first" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#171">source</a></span><a href="#method.first" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.first" class="fnname">first</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>T></h4></section></summary><div class="docblock"><p>Returns the first element of the slice, or <code>None</code> if it is empty.</p>
|
||
<h5 id="examples-12"><a href="#examples-12">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> [<span class="number">10</span>, <span class="number">40</span>, <span class="number">30</span>];
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">10</span>), <span class="ident">v</span>.<span class="ident">first</span>());
|
||
|
||
<span class="kw">let</span> <span class="ident">w</span>: <span class="kw-2">&</span>[<span class="ident">i32</span>] <span class="op">=</span> <span class="kw-2">&</span>[];
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">w</span>.<span class="ident">first</span>());</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.split_first" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.5.0">1.5.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#211">source</a></span><a href="#method.split_first" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.split_first" class="fnname">split_first</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>T, <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.tuple.html">)</a>></h4></section></summary><div class="docblock"><p>Returns the first and all the rest of the elements of the slice, or <code>None</code> if it is empty.</p>
|
||
<h5 id="examples-13"><a href="#examples-13">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="kw-2">&</span>[<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>];
|
||
|
||
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>((<span class="ident">first</span>, <span class="ident">elements</span>)) <span class="op">=</span> <span class="ident">x</span>.<span class="ident">split_first</span>() {
|
||
<span class="macro">assert_eq!</span>(<span class="ident">first</span>, <span class="kw-2">&</span><span class="number">0</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">elements</span>, <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">2</span>]);
|
||
}</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.split_last" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.5.0">1.5.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#253">source</a></span><a href="#method.split_last" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.split_last" class="fnname">split_last</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>T, <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.tuple.html">)</a>></h4></section></summary><div class="docblock"><p>Returns the last and all the rest of the elements of the slice, or <code>None</code> if it is empty.</p>
|
||
<h5 id="examples-14"><a href="#examples-14">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="kw-2">&</span>[<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>];
|
||
|
||
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>((<span class="ident">last</span>, <span class="ident">elements</span>)) <span class="op">=</span> <span class="ident">x</span>.<span class="ident">split_last</span>() {
|
||
<span class="macro">assert_eq!</span>(<span class="ident">last</span>, <span class="kw-2">&</span><span class="number">2</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">elements</span>, <span class="kw-2">&</span>[<span class="number">0</span>, <span class="number">1</span>]);
|
||
}</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.last" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#294">source</a></span><a href="#method.last" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.last" class="fnname">last</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>T></h4></section></summary><div class="docblock"><p>Returns the last element of the slice, or <code>None</code> if it is empty.</p>
|
||
<h5 id="examples-15"><a href="#examples-15">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> [<span class="number">10</span>, <span class="number">40</span>, <span class="number">30</span>];
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">30</span>), <span class="ident">v</span>.<span class="ident">last</span>());
|
||
|
||
<span class="kw">let</span> <span class="ident">w</span>: <span class="kw-2">&</span>[<span class="ident">i32</span>] <span class="op">=</span> <span class="kw-2">&</span>[];
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">w</span>.<span class="ident">last</span>());</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.get" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#339-341">source</a></span><a href="#method.get" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.get" class="fnname">get</a><I>(&self, index: I) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&<I as <a class="trait" href="https://doc.rust-lang.org/nightly/core/slice/index/trait.SliceIndex.html" title="trait core::slice::index::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">]</a>>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/slice/index/trait.SliceIndex.html#associatedtype.Output" title="type core::slice::index::SliceIndex::Output">Output</a>> <span class="where fmt-newline">where<br> I: <a class="trait" href="https://doc.rust-lang.org/nightly/core/slice/index/trait.SliceIndex.html" title="trait core::slice::index::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">]</a>>, </span></h4></section></summary><div class="docblock"><p>Returns a reference to an element or subslice depending on the type of
|
||
index.</p>
|
||
<ul>
|
||
<li>If given a position, returns a reference to the element at that
|
||
position or <code>None</code> if out of bounds.</li>
|
||
<li>If given a range, returns the subslice corresponding to that range,
|
||
or <code>None</code> if out of bounds.</li>
|
||
</ul>
|
||
<h5 id="examples-16"><a href="#examples-16">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> [<span class="number">10</span>, <span class="number">40</span>, <span class="number">30</span>];
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">40</span>), <span class="ident">v</span>.<span class="ident">get</span>(<span class="number">1</span>));
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="kw-2">&</span>[<span class="number">10</span>, <span class="number">40</span>][..]), <span class="ident">v</span>.<span class="ident">get</span>(<span class="number">0</span>..<span class="number">2</span>));
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">v</span>.<span class="ident">get</span>(<span class="number">3</span>));
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">v</span>.<span class="ident">get</span>(<span class="number">0</span>..<span class="number">4</span>));</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.get_unchecked" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#398-400">source</a></span><a href="#method.get_unchecked" class="anchor"></a><h4 class="code-header">pub unsafe fn <a href="#method.get_unchecked" class="fnname">get_unchecked</a><I>(<br> &self, <br> index: I<br>) -> &<I as <a class="trait" href="https://doc.rust-lang.org/nightly/core/slice/index/trait.SliceIndex.html" title="trait core::slice::index::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">]</a>>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/slice/index/trait.SliceIndex.html#associatedtype.Output" title="type core::slice::index::SliceIndex::Output">Output</a> <span class="where fmt-newline">where<br> I: <a class="trait" href="https://doc.rust-lang.org/nightly/core/slice/index/trait.SliceIndex.html" title="trait core::slice::index::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">]</a>>, </span></h4></section></summary><div class="docblock"><p>Returns a reference to an element or subslice, without doing bounds
|
||
checking.</p>
|
||
<p>For a safe alternative see <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.get"><code>get</code></a>.</p>
|
||
<h5 id="safety"><a href="#safety">Safety</a></h5>
|
||
<p>Calling this method with an out-of-bounds index is <em><a href="https://doc.rust-lang.org/reference/behavior-considered-undefined.html">undefined behavior</a></em>
|
||
even if the resulting reference is not used.</p>
|
||
<h5 id="examples-17"><a href="#examples-17">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">4</span>];
|
||
|
||
<span class="kw">unsafe</span> {
|
||
<span class="macro">assert_eq!</span>(<span class="ident">x</span>.<span class="ident">get_unchecked</span>(<span class="number">1</span>), <span class="kw-2">&</span><span class="number">2</span>);
|
||
}</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_ptr-1" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#476">source</a></span><a href="#method.as_ptr-1" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.as_ptr-1" class="fnname">as_ptr</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.pointer.html">*const T</a></h4></section></summary><div class="docblock"><p>Returns a raw pointer to the slice’s buffer.</p>
|
||
<p>The caller must ensure that the slice outlives the pointer this
|
||
function returns, or else it will end up pointing to garbage.</p>
|
||
<p>The caller must also ensure that the memory the pointer (non-transitively) points to
|
||
is never written to (except inside an <code>UnsafeCell</code>) using this pointer or any pointer
|
||
derived from it. If you need to mutate the contents of the slice, use <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.as_mut_ptr"><code>as_mut_ptr</code></a>.</p>
|
||
<p>Modifying the container referenced by this slice may cause its buffer
|
||
to be reallocated, which would also make any pointers to it invalid.</p>
|
||
<h5 id="examples-18"><a href="#examples-18">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">4</span>];
|
||
<span class="kw">let</span> <span class="ident">x_ptr</span> <span class="op">=</span> <span class="ident">x</span>.<span class="ident">as_ptr</span>();
|
||
|
||
<span class="kw">unsafe</span> {
|
||
<span class="kw">for</span> <span class="ident">i</span> <span class="kw">in</span> <span class="number">0</span>..<span class="ident">x</span>.<span class="ident">len</span>() {
|
||
<span class="macro">assert_eq!</span>(<span class="ident">x</span>.<span class="ident">get_unchecked</span>(<span class="ident">i</span>), <span class="kw-2">&</span><span class="kw-2">*</span><span class="ident">x_ptr</span>.<span class="ident">add</span>(<span class="ident">i</span>));
|
||
}
|
||
}</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_ptr_range" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.48.0">1.48.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#542">source</a></span><a href="#method.as_ptr_range" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.as_ptr_range" class="fnname">as_ptr_range</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.pointer.html">*const T</a>></h4></section></summary><div class="docblock"><p>Returns the two raw pointers spanning the slice.</p>
|
||
<p>The returned range is half-open, which means that the end pointer
|
||
points <em>one past</em> the last element of the slice. This way, an empty
|
||
slice is represented by two equal pointers, and the difference between
|
||
the two pointers represents the size of the slice.</p>
|
||
<p>See <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.as_ptr"><code>as_ptr</code></a> for warnings on using these pointers. The end pointer
|
||
requires extra caution, as it does not point to a valid element in the
|
||
slice.</p>
|
||
<p>This function is useful for interacting with foreign interfaces which
|
||
use two pointers to refer to a range of elements in memory, as is
|
||
common in C++.</p>
|
||
<p>It can also be useful to check if a pointer to an element refers to an
|
||
element of this slice:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="kw-2">&</span><span class="ident">a</span>[<span class="number">1</span>] <span class="kw">as</span> <span class="kw-2">*const</span> <span class="kw">_</span>;
|
||
<span class="kw">let</span> <span class="ident">y</span> <span class="op">=</span> <span class="kw-2">&</span><span class="number">5</span> <span class="kw">as</span> <span class="kw-2">*const</span> <span class="kw">_</span>;
|
||
|
||
<span class="macro">assert!</span>(<span class="ident">a</span>.<span class="ident">as_ptr_range</span>().<span class="ident">contains</span>(<span class="kw-2">&</span><span class="ident">x</span>));
|
||
<span class="macro">assert!</span>(<span class="op">!</span><span class="ident">a</span>.<span class="ident">as_ptr_range</span>().<span class="ident">contains</span>(<span class="kw-2">&</span><span class="ident">y</span>));</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.iter" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#732">source</a></span><a href="#method.iter" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.iter" class="fnname">iter</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/slice/iter/struct.Iter.html" title="struct core::slice::iter::Iter">Iter</a><'_, T></h4></section></summary><div class="docblock"><p>Returns an iterator over the slice.</p>
|
||
<h5 id="examples-19"><a href="#examples-19">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">4</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iterator</span> <span class="op">=</span> <span class="ident">x</span>.<span class="ident">iter</span>();
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iterator</span>.<span class="ident">next</span>(), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">1</span>));
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iterator</span>.<span class="ident">next</span>(), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">2</span>));
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iterator</span>.<span class="ident">next</span>(), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">4</span>));
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iterator</span>.<span class="ident">next</span>(), <span class="prelude-val">None</span>);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.windows" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#781">source</a></span><a href="#method.windows" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.windows" class="fnname">windows</a>(&self, size: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/slice/iter/struct.Windows.html" title="struct core::slice::iter::Windows">Windows</a><'_, T></h4></section></summary><div class="docblock"><p>Returns an iterator over all contiguous windows of length
|
||
<code>size</code>. The windows overlap. If the slice is shorter than
|
||
<code>size</code>, the iterator returns no values.</p>
|
||
<h5 id="panics-1"><a href="#panics-1">Panics</a></h5>
|
||
<p>Panics if <code>size</code> is 0.</p>
|
||
<h5 id="examples-20"><a href="#examples-20">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> [<span class="string">'r'</span>, <span class="string">'u'</span>, <span class="string">'s'</span>, <span class="string">'t'</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">windows</span>(<span class="number">2</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="string">'r'</span>, <span class="string">'u'</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="string">'u'</span>, <span class="string">'s'</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="string">'s'</span>, <span class="string">'t'</span>]);
|
||
<span class="macro">assert!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());</code></pre></div>
|
||
<p>If the slice is shorter than <code>size</code>:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> [<span class="string">'f'</span>, <span class="string">'o'</span>, <span class="string">'o'</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">windows</span>(<span class="number">4</span>);
|
||
<span class="macro">assert!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.chunks" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#815">source</a></span><a href="#method.chunks" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.chunks" class="fnname">chunks</a>(&self, chunk_size: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/slice/iter/struct.Chunks.html" title="struct core::slice::iter::Chunks">Chunks</a><'_, T></h4></section></summary><div class="docblock"><p>Returns an iterator over <code>chunk_size</code> elements of the slice at a time, starting at the
|
||
beginning of the slice.</p>
|
||
<p>The chunks are slices and do not overlap. If <code>chunk_size</code> does not divide the length of the
|
||
slice, then the last chunk will not have length <code>chunk_size</code>.</p>
|
||
<p>See <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.chunks_exact"><code>chunks_exact</code></a> for a variant of this iterator that returns chunks of always exactly
|
||
<code>chunk_size</code> elements, and <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.rchunks"><code>rchunks</code></a> for the same iterator but starting at the end of the
|
||
slice.</p>
|
||
<h5 id="panics-2"><a href="#panics-2">Panics</a></h5>
|
||
<p>Panics if <code>chunk_size</code> is 0.</p>
|
||
<h5 id="examples-21"><a href="#examples-21">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> [<span class="string">'l'</span>, <span class="string">'o'</span>, <span class="string">'r'</span>, <span class="string">'e'</span>, <span class="string">'m'</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">chunks</span>(<span class="number">2</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="string">'l'</span>, <span class="string">'o'</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="string">'r'</span>, <span class="string">'e'</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="string">'m'</span>]);
|
||
<span class="macro">assert!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.chunks_exact" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.31.0">1.31.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#890">source</a></span><a href="#method.chunks_exact" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.chunks_exact" class="fnname">chunks_exact</a>(&self, chunk_size: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/slice/iter/struct.ChunksExact.html" title="struct core::slice::iter::ChunksExact">ChunksExact</a><'_, T></h4></section></summary><div class="docblock"><p>Returns an iterator over <code>chunk_size</code> elements of the slice at a time, starting at the
|
||
beginning of the slice.</p>
|
||
<p>The chunks are slices and do not overlap. If <code>chunk_size</code> does not divide the length of the
|
||
slice, then the last up to <code>chunk_size-1</code> elements will be omitted and can be retrieved
|
||
from the <code>remainder</code> function of the iterator.</p>
|
||
<p>Due to each chunk having exactly <code>chunk_size</code> elements, the compiler can often optimize the
|
||
resulting code better than in the case of <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.chunks"><code>chunks</code></a>.</p>
|
||
<p>See <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.chunks"><code>chunks</code></a> for a variant of this iterator that also returns the remainder as a smaller
|
||
chunk, and <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.rchunks_exact"><code>rchunks_exact</code></a> for the same iterator but starting at the end of the slice.</p>
|
||
<h5 id="panics-3"><a href="#panics-3">Panics</a></h5>
|
||
<p>Panics if <code>chunk_size</code> is 0.</p>
|
||
<h5 id="examples-22"><a href="#examples-22">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> [<span class="string">'l'</span>, <span class="string">'o'</span>, <span class="string">'r'</span>, <span class="string">'e'</span>, <span class="string">'m'</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">chunks_exact</span>(<span class="number">2</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="string">'l'</span>, <span class="string">'o'</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="string">'r'</span>, <span class="string">'e'</span>]);
|
||
<span class="macro">assert!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">remainder</span>(), <span class="kw-2">&</span>[<span class="string">'m'</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_chunks_unchecked" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#967">source</a></span><a href="#method.as_chunks_unchecked" class="anchor"></a><h4 class="code-header">pub unsafe fn <a href="#method.as_chunks_unchecked" class="fnname">as_chunks_unchecked</a><const N: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.array.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.array.html">; N]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">]</a></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_as_chunks</code>)</div></span></summary><div class="docblock"><p>Splits the slice into a slice of <code>N</code>-element arrays,
|
||
assuming that there’s no remainder.</p>
|
||
<h5 id="safety-1"><a href="#safety-1">Safety</a></h5>
|
||
<p>This may only be called when</p>
|
||
<ul>
|
||
<li>The slice splits exactly into <code>N</code>-element chunks (aka <code>self.len() % N == 0</code>).</li>
|
||
<li><code>N != 0</code>.</li>
|
||
</ul>
|
||
<h5 id="examples-23"><a href="#examples-23">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">slice_as_chunks</span>)]</span>
|
||
<span class="kw">let</span> <span class="ident">slice</span>: <span class="kw-2">&</span>[<span class="ident">char</span>] <span class="op">=</span> <span class="kw-2">&</span>[<span class="string">'l'</span>, <span class="string">'o'</span>, <span class="string">'r'</span>, <span class="string">'e'</span>, <span class="string">'m'</span>, <span class="string">'!'</span>];
|
||
<span class="kw">let</span> <span class="ident">chunks</span>: <span class="kw-2">&</span>[[<span class="ident">char</span>; <span class="number">1</span>]] <span class="op">=</span>
|
||
<span class="comment">// SAFETY: 1-element chunks never have remainder</span>
|
||
<span class="kw">unsafe</span> { <span class="ident">slice</span>.<span class="ident">as_chunks_unchecked</span>() };
|
||
<span class="macro">assert_eq!</span>(<span class="ident">chunks</span>, <span class="kw-2">&</span>[[<span class="string">'l'</span>], [<span class="string">'o'</span>], [<span class="string">'r'</span>], [<span class="string">'e'</span>], [<span class="string">'m'</span>], [<span class="string">'!'</span>]]);
|
||
<span class="kw">let</span> <span class="ident">chunks</span>: <span class="kw-2">&</span>[[<span class="ident">char</span>; <span class="number">3</span>]] <span class="op">=</span>
|
||
<span class="comment">// SAFETY: The slice length (6) is a multiple of 3</span>
|
||
<span class="kw">unsafe</span> { <span class="ident">slice</span>.<span class="ident">as_chunks_unchecked</span>() };
|
||
<span class="macro">assert_eq!</span>(<span class="ident">chunks</span>, <span class="kw-2">&</span>[[<span class="string">'l'</span>, <span class="string">'o'</span>, <span class="string">'r'</span>], [<span class="string">'e'</span>, <span class="string">'m'</span>, <span class="string">'!'</span>]]);
|
||
|
||
<span class="comment">// These would be unsound:</span>
|
||
<span class="comment">// let chunks: &[[_; 5]] = slice.as_chunks_unchecked() // The slice length is not a multiple of 5</span>
|
||
<span class="comment">// let chunks: &[[_; 0]] = slice.as_chunks_unchecked() // Zero-length chunks are never allowed</span></code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_chunks" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#999">source</a></span><a href="#method.as_chunks" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.as_chunks" class="fnname">as_chunks</a><const N: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.array.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.array.html">; N]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.tuple.html">)</a></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_as_chunks</code>)</div></span></summary><div class="docblock"><p>Splits the slice into a slice of <code>N</code>-element arrays,
|
||
starting at the beginning of the slice,
|
||
and a remainder slice with length strictly less than <code>N</code>.</p>
|
||
<h5 id="panics-4"><a href="#panics-4">Panics</a></h5>
|
||
<p>Panics if <code>N</code> is 0. This check will most probably get changed to a compile time
|
||
error before this method gets stabilized.</p>
|
||
<h5 id="examples-24"><a href="#examples-24">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">slice_as_chunks</span>)]</span>
|
||
<span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> [<span class="string">'l'</span>, <span class="string">'o'</span>, <span class="string">'r'</span>, <span class="string">'e'</span>, <span class="string">'m'</span>];
|
||
<span class="kw">let</span> (<span class="ident">chunks</span>, <span class="ident">remainder</span>) <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">as_chunks</span>();
|
||
<span class="macro">assert_eq!</span>(<span class="ident">chunks</span>, <span class="kw-2">&</span>[[<span class="string">'l'</span>, <span class="string">'o'</span>], [<span class="string">'r'</span>, <span class="string">'e'</span>]]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">remainder</span>, <span class="kw-2">&</span>[<span class="string">'m'</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_rchunks" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1030">source</a></span><a href="#method.as_rchunks" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.as_rchunks" class="fnname">as_rchunks</a><const N: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[T]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.array.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.array.html">; N]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.tuple.html">)</a></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_as_chunks</code>)</div></span></summary><div class="docblock"><p>Splits the slice into a slice of <code>N</code>-element arrays,
|
||
starting at the end of the slice,
|
||
and a remainder slice with length strictly less than <code>N</code>.</p>
|
||
<h5 id="panics-5"><a href="#panics-5">Panics</a></h5>
|
||
<p>Panics if <code>N</code> is 0. This check will most probably get changed to a compile time
|
||
error before this method gets stabilized.</p>
|
||
<h5 id="examples-25"><a href="#examples-25">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">slice_as_chunks</span>)]</span>
|
||
<span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> [<span class="string">'l'</span>, <span class="string">'o'</span>, <span class="string">'r'</span>, <span class="string">'e'</span>, <span class="string">'m'</span>];
|
||
<span class="kw">let</span> (<span class="ident">remainder</span>, <span class="ident">chunks</span>) <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">as_rchunks</span>();
|
||
<span class="macro">assert_eq!</span>(<span class="ident">remainder</span>, <span class="kw-2">&</span>[<span class="string">'l'</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">chunks</span>, <span class="kw-2">&</span>[[<span class="string">'o'</span>, <span class="string">'r'</span>], [<span class="string">'e'</span>, <span class="string">'m'</span>]]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.array_chunks" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1069">source</a></span><a href="#method.array_chunks" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.array_chunks" class="fnname">array_chunks</a><const N: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/slice/iter/struct.ArrayChunks.html" title="struct core::slice::iter::ArrayChunks">ArrayChunks</a><'_, T, N></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>array_chunks</code>)</div></span></summary><div class="docblock"><p>Returns an iterator over <code>N</code> elements of the slice at a time, starting at the
|
||
beginning of the slice.</p>
|
||
<p>The chunks are array references and do not overlap. If <code>N</code> does not divide the
|
||
length of the slice, then the last up to <code>N-1</code> elements will be omitted and can be
|
||
retrieved from the <code>remainder</code> function of the iterator.</p>
|
||
<p>This method is the const generic equivalent of <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.chunks_exact"><code>chunks_exact</code></a>.</p>
|
||
<h5 id="panics-6"><a href="#panics-6">Panics</a></h5>
|
||
<p>Panics if <code>N</code> is 0. This check will most probably get changed to a compile time
|
||
error before this method gets stabilized.</p>
|
||
<h5 id="examples-26"><a href="#examples-26">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">array_chunks</span>)]</span>
|
||
<span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> [<span class="string">'l'</span>, <span class="string">'o'</span>, <span class="string">'r'</span>, <span class="string">'e'</span>, <span class="string">'m'</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">array_chunks</span>();
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="string">'l'</span>, <span class="string">'o'</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="string">'r'</span>, <span class="string">'e'</span>]);
|
||
<span class="macro">assert!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">remainder</span>(), <span class="kw-2">&</span>[<span class="string">'m'</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.array_windows" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1254">source</a></span><a href="#method.array_windows" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.array_windows" class="fnname">array_windows</a><const N: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/slice/iter/struct.ArrayWindows.html" title="struct core::slice::iter::ArrayWindows">ArrayWindows</a><'_, T, N></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>array_windows</code>)</div></span></summary><div class="docblock"><p>Returns an iterator over overlapping windows of <code>N</code> elements of a slice,
|
||
starting at the beginning of the slice.</p>
|
||
<p>This is the const generic equivalent of <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.windows"><code>windows</code></a>.</p>
|
||
<p>If <code>N</code> is greater than the size of the slice, it will return no windows.</p>
|
||
<h5 id="panics-7"><a href="#panics-7">Panics</a></h5>
|
||
<p>Panics if <code>N</code> is 0. This check will most probably get changed to a compile time
|
||
error before this method gets stabilized.</p>
|
||
<h5 id="examples-27"><a href="#examples-27">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">array_windows</span>)]</span>
|
||
<span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> [<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">array_windows</span>();
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="number">0</span>, <span class="number">1</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">2</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="number">2</span>, <span class="number">3</span>]);
|
||
<span class="macro">assert!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.rchunks" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.31.0">1.31.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1288">source</a></span><a href="#method.rchunks" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.rchunks" class="fnname">rchunks</a>(&self, chunk_size: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/slice/iter/struct.RChunks.html" title="struct core::slice::iter::RChunks">RChunks</a><'_, T></h4></section></summary><div class="docblock"><p>Returns an iterator over <code>chunk_size</code> elements of the slice at a time, starting at the end
|
||
of the slice.</p>
|
||
<p>The chunks are slices and do not overlap. If <code>chunk_size</code> does not divide the length of the
|
||
slice, then the last chunk will not have length <code>chunk_size</code>.</p>
|
||
<p>See <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.rchunks_exact"><code>rchunks_exact</code></a> for a variant of this iterator that returns chunks of always exactly
|
||
<code>chunk_size</code> elements, and <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.chunks"><code>chunks</code></a> for the same iterator but starting at the beginning
|
||
of the slice.</p>
|
||
<h5 id="panics-8"><a href="#panics-8">Panics</a></h5>
|
||
<p>Panics if <code>chunk_size</code> is 0.</p>
|
||
<h5 id="examples-28"><a href="#examples-28">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> [<span class="string">'l'</span>, <span class="string">'o'</span>, <span class="string">'r'</span>, <span class="string">'e'</span>, <span class="string">'m'</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">rchunks</span>(<span class="number">2</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="string">'e'</span>, <span class="string">'m'</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="string">'o'</span>, <span class="string">'r'</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="string">'l'</span>]);
|
||
<span class="macro">assert!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.rchunks_exact" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.31.0">1.31.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1365">source</a></span><a href="#method.rchunks_exact" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.rchunks_exact" class="fnname">rchunks_exact</a>(&self, chunk_size: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/slice/iter/struct.RChunksExact.html" title="struct core::slice::iter::RChunksExact">RChunksExact</a><'_, T></h4></section></summary><div class="docblock"><p>Returns an iterator over <code>chunk_size</code> elements of the slice at a time, starting at the
|
||
end of the slice.</p>
|
||
<p>The chunks are slices and do not overlap. If <code>chunk_size</code> does not divide the length of the
|
||
slice, then the last up to <code>chunk_size-1</code> elements will be omitted and can be retrieved
|
||
from the <code>remainder</code> function of the iterator.</p>
|
||
<p>Due to each chunk having exactly <code>chunk_size</code> elements, the compiler can often optimize the
|
||
resulting code better than in the case of <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.chunks"><code>chunks</code></a>.</p>
|
||
<p>See <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.rchunks"><code>rchunks</code></a> for a variant of this iterator that also returns the remainder as a smaller
|
||
chunk, and <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.chunks_exact"><code>chunks_exact</code></a> for the same iterator but starting at the beginning of the
|
||
slice.</p>
|
||
<h5 id="panics-9"><a href="#panics-9">Panics</a></h5>
|
||
<p>Panics if <code>chunk_size</code> is 0.</p>
|
||
<h5 id="examples-29"><a href="#examples-29">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> [<span class="string">'l'</span>, <span class="string">'o'</span>, <span class="string">'r'</span>, <span class="string">'e'</span>, <span class="string">'m'</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">rchunks_exact</span>(<span class="number">2</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="string">'e'</span>, <span class="string">'m'</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="string">'o'</span>, <span class="string">'r'</span>]);
|
||
<span class="macro">assert!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">remainder</span>(), <span class="kw-2">&</span>[<span class="string">'l'</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.group_by" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1451-1453">source</a></span><a href="#method.group_by" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.group_by" class="fnname">group_by</a><F>(&self, pred: F) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/slice/iter/struct.GroupBy.html" title="struct core::slice::iter::GroupBy">GroupBy</a><'_, T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>T, <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a>, </span></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_group_by</code>)</div></span></summary><div class="docblock"><p>Returns an iterator over the slice producing non-overlapping runs
|
||
of elements using the predicate to separate them.</p>
|
||
<p>The predicate is called on two elements following themselves,
|
||
it means the predicate is called on <code>slice[0]</code> and <code>slice[1]</code>
|
||
then on <code>slice[1]</code> and <code>slice[2]</code> and so on.</p>
|
||
<h5 id="examples-30"><a href="#examples-30">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">slice_group_by</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">3</span>, <span class="number">3</span>, <span class="number">2</span>, <span class="number">2</span>, <span class="number">2</span>];
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">group_by</span>(<span class="op">|</span><span class="ident">a</span>, <span class="ident">b</span><span class="op">|</span> <span class="ident">a</span> <span class="op">==</span> <span class="ident">b</span>);
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>(), <span class="prelude-val">Some</span>(<span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>][..]));
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>(), <span class="prelude-val">Some</span>(<span class="kw-2">&</span>[<span class="number">3</span>, <span class="number">3</span>][..]));
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>(), <span class="prelude-val">Some</span>(<span class="kw-2">&</span>[<span class="number">2</span>, <span class="number">2</span>, <span class="number">2</span>][..]));
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>(), <span class="prelude-val">None</span>);</code></pre></div>
|
||
<p>This method can be used to extract the sorted subslices:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">slice_group_by</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>];
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">group_by</span>(<span class="op">|</span><span class="ident">a</span>, <span class="ident">b</span><span class="op">|</span> <span class="ident">a</span> <span class="op"><</span><span class="op">=</span> <span class="ident">b</span>);
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>(), <span class="prelude-val">Some</span>(<span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>][..]));
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>(), <span class="prelude-val">Some</span>(<span class="kw-2">&</span>[<span class="number">2</span>, <span class="number">3</span>][..]));
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>(), <span class="prelude-val">Some</span>(<span class="kw-2">&</span>[<span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>][..]));
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>(), <span class="prelude-val">None</span>);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.split_at" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1540">source</a></span><a href="#method.split_at" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.split_at" class="fnname">split_at</a>(&self, mid: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[T]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.tuple.html">)</a></h4></section></summary><div class="docblock"><p>Divides one slice into two at an index.</p>
|
||
<p>The first will contain all indices from <code>[0, mid)</code> (excluding
|
||
the index <code>mid</code> itself) and the second will contain all
|
||
indices from <code>[mid, len)</code> (excluding the index <code>len</code> itself).</p>
|
||
<h5 id="panics-10"><a href="#panics-10">Panics</a></h5>
|
||
<p>Panics if <code>mid > len</code>.</p>
|
||
<h5 id="examples-31"><a href="#examples-31">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>];
|
||
|
||
{
|
||
<span class="kw">let</span> (<span class="ident">left</span>, <span class="ident">right</span>) <span class="op">=</span> <span class="ident">v</span>.<span class="ident">split_at</span>(<span class="number">0</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">left</span>, []);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">right</span>, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]);
|
||
}
|
||
|
||
{
|
||
<span class="kw">let</span> (<span class="ident">left</span>, <span class="ident">right</span>) <span class="op">=</span> <span class="ident">v</span>.<span class="ident">split_at</span>(<span class="number">2</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">left</span>, [<span class="number">1</span>, <span class="number">2</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">right</span>, [<span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]);
|
||
}
|
||
|
||
{
|
||
<span class="kw">let</span> (<span class="ident">left</span>, <span class="ident">right</span>) <span class="op">=</span> <span class="ident">v</span>.<span class="ident">split_at</span>(<span class="number">6</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">left</span>, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">right</span>, []);
|
||
}</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.split_at_unchecked" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1624">source</a></span><a href="#method.split_at_unchecked" class="anchor"></a><h4 class="code-header">pub unsafe fn <a href="#method.split_at_unchecked" class="fnname">split_at_unchecked</a>(&self, mid: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[T]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.tuple.html">)</a></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_split_at_unchecked</code>)</div></span></summary><div class="docblock"><p>Divides one slice into two at an index, without doing bounds checking.</p>
|
||
<p>The first will contain all indices from <code>[0, mid)</code> (excluding
|
||
the index <code>mid</code> itself) and the second will contain all
|
||
indices from <code>[mid, len)</code> (excluding the index <code>len</code> itself).</p>
|
||
<p>For a safe alternative see <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.split_at"><code>split_at</code></a>.</p>
|
||
<h5 id="safety-2"><a href="#safety-2">Safety</a></h5>
|
||
<p>Calling this method with an out-of-bounds index is <em><a href="https://doc.rust-lang.org/reference/behavior-considered-undefined.html">undefined behavior</a></em>
|
||
even if the resulting reference is not used. The caller has to ensure that
|
||
<code>0 <= mid <= self.len()</code>.</p>
|
||
<h5 id="examples-32"><a href="#examples-32">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">slice_split_at_unchecked</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>];
|
||
|
||
<span class="kw">unsafe</span> {
|
||
<span class="kw">let</span> (<span class="ident">left</span>, <span class="ident">right</span>) <span class="op">=</span> <span class="ident">v</span>.<span class="ident">split_at_unchecked</span>(<span class="number">0</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">left</span>, []);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">right</span>, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]);
|
||
}
|
||
|
||
<span class="kw">unsafe</span> {
|
||
<span class="kw">let</span> (<span class="ident">left</span>, <span class="ident">right</span>) <span class="op">=</span> <span class="ident">v</span>.<span class="ident">split_at_unchecked</span>(<span class="number">2</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">left</span>, [<span class="number">1</span>, <span class="number">2</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">right</span>, [<span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]);
|
||
}
|
||
|
||
<span class="kw">unsafe</span> {
|
||
<span class="kw">let</span> (<span class="ident">left</span>, <span class="ident">right</span>) <span class="op">=</span> <span class="ident">v</span>.<span class="ident">split_at_unchecked</span>(<span class="number">6</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">left</span>, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">right</span>, []);
|
||
}</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.split_array_ref" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1718">source</a></span><a href="#method.split_array_ref" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.split_array_ref" class="fnname">split_array_ref</a><const N: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.tuple.html">(</a>&<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.array.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.array.html">; N]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.tuple.html">)</a></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>split_array</code>)</div></span></summary><div class="docblock"><p>Divides one slice into an array and a remainder slice at an index.</p>
|
||
<p>The array will contain all indices from <code>[0, N)</code> (excluding
|
||
the index <code>N</code> itself) and the slice will contain all
|
||
indices from <code>[N, len)</code> (excluding the index <code>len</code> itself).</p>
|
||
<h5 id="panics-11"><a href="#panics-11">Panics</a></h5>
|
||
<p>Panics if <code>N > len</code>.</p>
|
||
<h5 id="examples-33"><a href="#examples-33">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">split_array</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>][..];
|
||
|
||
{
|
||
<span class="kw">let</span> (<span class="ident">left</span>, <span class="ident">right</span>) <span class="op">=</span> <span class="ident">v</span>.<span class="ident">split_array_ref</span>::<span class="op"><</span><span class="number">0</span><span class="op">></span>();
|
||
<span class="macro">assert_eq!</span>(<span class="ident">left</span>, <span class="kw-2">&</span>[]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">right</span>, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]);
|
||
}
|
||
|
||
{
|
||
<span class="kw">let</span> (<span class="ident">left</span>, <span class="ident">right</span>) <span class="op">=</span> <span class="ident">v</span>.<span class="ident">split_array_ref</span>::<span class="op"><</span><span class="number">2</span><span class="op">></span>();
|
||
<span class="macro">assert_eq!</span>(<span class="ident">left</span>, <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">2</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">right</span>, [<span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]);
|
||
}
|
||
|
||
{
|
||
<span class="kw">let</span> (<span class="ident">left</span>, <span class="ident">right</span>) <span class="op">=</span> <span class="ident">v</span>.<span class="ident">split_array_ref</span>::<span class="op"><</span><span class="number">6</span><span class="op">></span>();
|
||
<span class="macro">assert_eq!</span>(<span class="ident">left</span>, <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">right</span>, []);
|
||
}</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.rsplit_array_ref" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1796">source</a></span><a href="#method.rsplit_array_ref" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.rsplit_array_ref" class="fnname">rsplit_array_ref</a><const N: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[T]</a>, &<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.array.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.array.html">; N]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.tuple.html">)</a></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>split_array</code>)</div></span></summary><div class="docblock"><p>Divides one slice into an array and a remainder slice at an index from
|
||
the end.</p>
|
||
<p>The slice will contain all indices from <code>[0, len - N)</code> (excluding
|
||
the index <code>len - N</code> itself) and the array will contain all
|
||
indices from <code>[len - N, len)</code> (excluding the index <code>len</code> itself).</p>
|
||
<h5 id="panics-12"><a href="#panics-12">Panics</a></h5>
|
||
<p>Panics if <code>N > len</code>.</p>
|
||
<h5 id="examples-34"><a href="#examples-34">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">split_array</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>][..];
|
||
|
||
{
|
||
<span class="kw">let</span> (<span class="ident">left</span>, <span class="ident">right</span>) <span class="op">=</span> <span class="ident">v</span>.<span class="ident">rsplit_array_ref</span>::<span class="op"><</span><span class="number">0</span><span class="op">></span>();
|
||
<span class="macro">assert_eq!</span>(<span class="ident">left</span>, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">right</span>, <span class="kw-2">&</span>[]);
|
||
}
|
||
|
||
{
|
||
<span class="kw">let</span> (<span class="ident">left</span>, <span class="ident">right</span>) <span class="op">=</span> <span class="ident">v</span>.<span class="ident">rsplit_array_ref</span>::<span class="op"><</span><span class="number">2</span><span class="op">></span>();
|
||
<span class="macro">assert_eq!</span>(<span class="ident">left</span>, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">right</span>, <span class="kw-2">&</span>[<span class="number">5</span>, <span class="number">6</span>]);
|
||
}
|
||
|
||
{
|
||
<span class="kw">let</span> (<span class="ident">left</span>, <span class="ident">right</span>) <span class="op">=</span> <span class="ident">v</span>.<span class="ident">rsplit_array_ref</span>::<span class="op"><</span><span class="number">6</span><span class="op">></span>();
|
||
<span class="macro">assert_eq!</span>(<span class="ident">left</span>, []);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">right</span>, <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]);
|
||
}</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.split" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1879-1881">source</a></span><a href="#method.split" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.split" class="fnname">split</a><F>(&self, pred: F) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/slice/iter/struct.Split.html" title="struct core::slice::iter::Split">Split</a><'_, T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a>, </span></h4></section></summary><div class="docblock"><p>Returns an iterator over subslices separated by elements that match
|
||
<code>pred</code>. The matched element is not contained in the subslices.</p>
|
||
<h5 id="examples-35"><a href="#examples-35">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> [<span class="number">10</span>, <span class="number">40</span>, <span class="number">33</span>, <span class="number">20</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">split</span>(<span class="op">|</span><span class="ident">num</span><span class="op">|</span> <span class="ident">num</span> <span class="op">%</span> <span class="number">3</span> <span class="op">==</span> <span class="number">0</span>);
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="number">10</span>, <span class="number">40</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="number">20</span>]);
|
||
<span class="macro">assert!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());</code></pre></div>
|
||
<p>If the first element is matched, an empty slice will be the first item
|
||
returned by the iterator. Similarly, if the last element in the slice
|
||
is matched, an empty slice will be the last item returned by the
|
||
iterator:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> [<span class="number">10</span>, <span class="number">40</span>, <span class="number">33</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">split</span>(<span class="op">|</span><span class="ident">num</span><span class="op">|</span> <span class="ident">num</span> <span class="op">%</span> <span class="number">3</span> <span class="op">==</span> <span class="number">0</span>);
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="number">10</span>, <span class="number">40</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[]);
|
||
<span class="macro">assert!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());</code></pre></div>
|
||
<p>If two matched elements are directly adjacent, an empty slice will be
|
||
present between them:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> [<span class="number">10</span>, <span class="number">6</span>, <span class="number">33</span>, <span class="number">20</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">split</span>(<span class="op">|</span><span class="ident">num</span><span class="op">|</span> <span class="ident">num</span> <span class="op">%</span> <span class="number">3</span> <span class="op">==</span> <span class="number">0</span>);
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="number">10</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="number">20</span>]);
|
||
<span class="macro">assert!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.split_inclusive" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.51.0">1.51.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1937-1939">source</a></span><a href="#method.split_inclusive" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.split_inclusive" class="fnname">split_inclusive</a><F>(&self, pred: F) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/slice/iter/struct.SplitInclusive.html" title="struct core::slice::iter::SplitInclusive">SplitInclusive</a><'_, T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a>, </span></h4></section></summary><div class="docblock"><p>Returns an iterator over subslices separated by elements that match
|
||
<code>pred</code>. The matched element is contained in the end of the previous
|
||
subslice as a terminator.</p>
|
||
<h5 id="examples-36"><a href="#examples-36">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> [<span class="number">10</span>, <span class="number">40</span>, <span class="number">33</span>, <span class="number">20</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">split_inclusive</span>(<span class="op">|</span><span class="ident">num</span><span class="op">|</span> <span class="ident">num</span> <span class="op">%</span> <span class="number">3</span> <span class="op">==</span> <span class="number">0</span>);
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="number">10</span>, <span class="number">40</span>, <span class="number">33</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="number">20</span>]);
|
||
<span class="macro">assert!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());</code></pre></div>
|
||
<p>If the last element of the slice is matched,
|
||
that element will be considered the terminator of the preceding slice.
|
||
That slice will be the last item returned by the iterator.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> [<span class="number">3</span>, <span class="number">10</span>, <span class="number">40</span>, <span class="number">33</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">split_inclusive</span>(<span class="op">|</span><span class="ident">num</span><span class="op">|</span> <span class="ident">num</span> <span class="op">%</span> <span class="number">3</span> <span class="op">==</span> <span class="number">0</span>);
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="number">3</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="number">10</span>, <span class="number">40</span>, <span class="number">33</span>]);
|
||
<span class="macro">assert!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.rsplit" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.27.0">1.27.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1997-1999">source</a></span><a href="#method.rsplit" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.rsplit" class="fnname">rsplit</a><F>(&self, pred: F) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/slice/iter/struct.RSplit.html" title="struct core::slice::iter::RSplit">RSplit</a><'_, T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a>, </span></h4></section></summary><div class="docblock"><p>Returns an iterator over subslices separated by elements that match
|
||
<code>pred</code>, starting at the end of the slice and working backwards.
|
||
The matched element is not contained in the subslices.</p>
|
||
<h5 id="examples-37"><a href="#examples-37">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> [<span class="number">11</span>, <span class="number">22</span>, <span class="number">33</span>, <span class="number">0</span>, <span class="number">44</span>, <span class="number">55</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">iter</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">rsplit</span>(<span class="op">|</span><span class="ident">num</span><span class="op">|</span> <span class="kw-2">*</span><span class="ident">num</span> <span class="op">==</span> <span class="number">0</span>);
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="number">44</span>, <span class="number">55</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="number">11</span>, <span class="number">22</span>, <span class="number">33</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">iter</span>.<span class="ident">next</span>(), <span class="prelude-val">None</span>);</code></pre></div>
|
||
<p>As with <code>split()</code>, if the first or last element is matched, an empty
|
||
slice will be the first (or last) item returned by the iterator.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&</span>[<span class="number">0</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">8</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">it</span> <span class="op">=</span> <span class="ident">v</span>.<span class="ident">rsplit</span>(<span class="op">|</span><span class="ident">n</span><span class="op">|</span> <span class="kw-2">*</span><span class="ident">n</span> <span class="op">%</span> <span class="number">2</span> <span class="op">==</span> <span class="number">0</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">it</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">it</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="number">3</span>, <span class="number">5</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">it</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">1</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">it</span>.<span class="ident">next</span>().<span class="ident">unwrap</span>(), <span class="kw-2">&</span>[]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">it</span>.<span class="ident">next</span>(), <span class="prelude-val">None</span>);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.splitn" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2051-2053">source</a></span><a href="#method.splitn" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.splitn" class="fnname">splitn</a><F>(&self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>, pred: F) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/slice/iter/struct.SplitN.html" title="struct core::slice::iter::SplitN">SplitN</a><'_, T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a>, </span></h4></section></summary><div class="docblock"><p>Returns an iterator over subslices separated by elements that match
|
||
<code>pred</code>, limited to returning at most <code>n</code> items. The matched element is
|
||
not contained in the subslices.</p>
|
||
<p>The last element returned, if any, will contain the remainder of the
|
||
slice.</p>
|
||
<h5 id="examples-38"><a href="#examples-38">Examples</a></h5>
|
||
<p>Print the slice split once by numbers divisible by 3 (i.e., <code>[10, 40]</code>,
|
||
<code>[20, 60, 50]</code>):</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> [<span class="number">10</span>, <span class="number">40</span>, <span class="number">30</span>, <span class="number">20</span>, <span class="number">60</span>, <span class="number">50</span>];
|
||
|
||
<span class="kw">for</span> <span class="ident">group</span> <span class="kw">in</span> <span class="ident">v</span>.<span class="ident">splitn</span>(<span class="number">2</span>, <span class="op">|</span><span class="ident">num</span><span class="op">|</span> <span class="kw-2">*</span><span class="ident">num</span> <span class="op">%</span> <span class="number">3</span> <span class="op">==</span> <span class="number">0</span>) {
|
||
<span class="macro">println!</span>(<span class="string">"{group:?}"</span>);
|
||
}</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.rsplitn" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2106-2108">source</a></span><a href="#method.rsplitn" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.rsplitn" class="fnname">rsplitn</a><F>(&self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>, pred: F) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/slice/iter/struct.RSplitN.html" title="struct core::slice::iter::RSplitN">RSplitN</a><'_, T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a>, </span></h4></section></summary><div class="docblock"><p>Returns an iterator over subslices separated by elements that match
|
||
<code>pred</code> limited to returning at most <code>n</code> items. This starts at the end of
|
||
the slice and works backwards. The matched element is not contained in
|
||
the subslices.</p>
|
||
<p>The last element returned, if any, will contain the remainder of the
|
||
slice.</p>
|
||
<h5 id="examples-39"><a href="#examples-39">Examples</a></h5>
|
||
<p>Print the slice split once, starting from the end, by numbers divisible
|
||
by 3 (i.e., <code>[50]</code>, <code>[10, 40, 30, 20]</code>):</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> [<span class="number">10</span>, <span class="number">40</span>, <span class="number">30</span>, <span class="number">20</span>, <span class="number">60</span>, <span class="number">50</span>];
|
||
|
||
<span class="kw">for</span> <span class="ident">group</span> <span class="kw">in</span> <span class="ident">v</span>.<span class="ident">rsplitn</span>(<span class="number">2</span>, <span class="op">|</span><span class="ident">num</span><span class="op">|</span> <span class="kw-2">*</span><span class="ident">num</span> <span class="op">%</span> <span class="number">3</span> <span class="op">==</span> <span class="number">0</span>) {
|
||
<span class="macro">println!</span>(<span class="string">"{group:?}"</span>);
|
||
}</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.contains" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2162-2164">source</a></span><a href="#method.contains" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.contains" class="fnname">contains</a>(&self, x: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><T>, </span></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if the slice contains an element with the given value.</p>
|
||
<h5 id="examples-40"><a href="#examples-40">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> [<span class="number">10</span>, <span class="number">40</span>, <span class="number">30</span>];
|
||
<span class="macro">assert!</span>(<span class="ident">v</span>.<span class="ident">contains</span>(<span class="kw-2">&</span><span class="number">30</span>));
|
||
<span class="macro">assert!</span>(<span class="op">!</span><span class="ident">v</span>.<span class="ident">contains</span>(<span class="kw-2">&</span><span class="number">50</span>));</code></pre></div>
|
||
<p>If you do not have a <code>&T</code>, but some other value that you can compare
|
||
with one (for example, <code>String</code> implements <code>PartialEq<str></code>), you can
|
||
use <code>iter().any</code>:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> [<span class="ident">String::from</span>(<span class="string">"hello"</span>), <span class="ident">String::from</span>(<span class="string">"world"</span>)]; <span class="comment">// slice of `String`</span>
|
||
<span class="macro">assert!</span>(<span class="ident">v</span>.<span class="ident">iter</span>().<span class="ident">any</span>(<span class="op">|</span><span class="ident">e</span><span class="op">|</span> <span class="ident">e</span> <span class="op">==</span> <span class="string">"hello"</span>)); <span class="comment">// search with `&str`</span>
|
||
<span class="macro">assert!</span>(<span class="op">!</span><span class="ident">v</span>.<span class="ident">iter</span>().<span class="ident">any</span>(<span class="op">|</span><span class="ident">e</span><span class="op">|</span> <span class="ident">e</span> <span class="op">==</span> <span class="string">"hi"</span>));</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.starts_with" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2191-2193">source</a></span><a href="#method.starts_with" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.starts_with" class="fnname">starts_with</a>(&self, needle: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[T]</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><T>, </span></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if <code>needle</code> is a prefix of the slice.</p>
|
||
<h5 id="examples-41"><a href="#examples-41">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> [<span class="number">10</span>, <span class="number">40</span>, <span class="number">30</span>];
|
||
<span class="macro">assert!</span>(<span class="ident">v</span>.<span class="ident">starts_with</span>(<span class="kw-2">&</span>[<span class="number">10</span>]));
|
||
<span class="macro">assert!</span>(<span class="ident">v</span>.<span class="ident">starts_with</span>(<span class="kw-2">&</span>[<span class="number">10</span>, <span class="number">40</span>]));
|
||
<span class="macro">assert!</span>(<span class="op">!</span><span class="ident">v</span>.<span class="ident">starts_with</span>(<span class="kw-2">&</span>[<span class="number">50</span>]));
|
||
<span class="macro">assert!</span>(<span class="op">!</span><span class="ident">v</span>.<span class="ident">starts_with</span>(<span class="kw-2">&</span>[<span class="number">10</span>, <span class="number">50</span>]));</code></pre></div>
|
||
<p>Always returns <code>true</code> if <code>needle</code> is an empty slice:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&</span>[<span class="number">10</span>, <span class="number">40</span>, <span class="number">30</span>];
|
||
<span class="macro">assert!</span>(<span class="ident">v</span>.<span class="ident">starts_with</span>(<span class="kw-2">&</span>[]));
|
||
<span class="kw">let</span> <span class="ident">v</span>: <span class="kw-2">&</span>[<span class="ident">u8</span>] <span class="op">=</span> <span class="kw-2">&</span>[];
|
||
<span class="macro">assert!</span>(<span class="ident">v</span>.<span class="ident">starts_with</span>(<span class="kw-2">&</span>[]));</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.ends_with" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2221-2223">source</a></span><a href="#method.ends_with" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.ends_with" class="fnname">ends_with</a>(&self, needle: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[T]</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><T>, </span></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if <code>needle</code> is a suffix of the slice.</p>
|
||
<h5 id="examples-42"><a href="#examples-42">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> [<span class="number">10</span>, <span class="number">40</span>, <span class="number">30</span>];
|
||
<span class="macro">assert!</span>(<span class="ident">v</span>.<span class="ident">ends_with</span>(<span class="kw-2">&</span>[<span class="number">30</span>]));
|
||
<span class="macro">assert!</span>(<span class="ident">v</span>.<span class="ident">ends_with</span>(<span class="kw-2">&</span>[<span class="number">40</span>, <span class="number">30</span>]));
|
||
<span class="macro">assert!</span>(<span class="op">!</span><span class="ident">v</span>.<span class="ident">ends_with</span>(<span class="kw-2">&</span>[<span class="number">50</span>]));
|
||
<span class="macro">assert!</span>(<span class="op">!</span><span class="ident">v</span>.<span class="ident">ends_with</span>(<span class="kw-2">&</span>[<span class="number">50</span>, <span class="number">30</span>]));</code></pre></div>
|
||
<p>Always returns <code>true</code> if <code>needle</code> is an empty slice:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&</span>[<span class="number">10</span>, <span class="number">40</span>, <span class="number">30</span>];
|
||
<span class="macro">assert!</span>(<span class="ident">v</span>.<span class="ident">ends_with</span>(<span class="kw-2">&</span>[]));
|
||
<span class="kw">let</span> <span class="ident">v</span>: <span class="kw-2">&</span>[<span class="ident">u8</span>] <span class="op">=</span> <span class="kw-2">&</span>[];
|
||
<span class="macro">assert!</span>(<span class="ident">v</span>.<span class="ident">ends_with</span>(<span class="kw-2">&</span>[]));</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.strip_prefix" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.51.0">1.51.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2251-2253">source</a></span><a href="#method.strip_prefix" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.strip_prefix" class="fnname">strip_prefix</a><P>(&self, prefix: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>P) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[T]</a>> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/slice/trait.SlicePattern.html" title="trait core::slice::SlicePattern">SlicePattern</a><Item = T> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><T>, </span></h4></section></summary><div class="docblock"><p>Returns a subslice with the prefix removed.</p>
|
||
<p>If the slice starts with <code>prefix</code>, returns the subslice after the prefix, wrapped in <code>Some</code>.
|
||
If <code>prefix</code> is empty, simply returns the original slice.</p>
|
||
<p>If the slice does not start with <code>prefix</code>, returns <code>None</code>.</p>
|
||
<h5 id="examples-43"><a href="#examples-43">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&</span>[<span class="number">10</span>, <span class="number">40</span>, <span class="number">30</span>];
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>.<span class="ident">strip_prefix</span>(<span class="kw-2">&</span>[<span class="number">10</span>]), <span class="prelude-val">Some</span>(<span class="kw-2">&</span>[<span class="number">40</span>, <span class="number">30</span>][..]));
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>.<span class="ident">strip_prefix</span>(<span class="kw-2">&</span>[<span class="number">10</span>, <span class="number">40</span>]), <span class="prelude-val">Some</span>(<span class="kw-2">&</span>[<span class="number">30</span>][..]));
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>.<span class="ident">strip_prefix</span>(<span class="kw-2">&</span>[<span class="number">50</span>]), <span class="prelude-val">None</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>.<span class="ident">strip_prefix</span>(<span class="kw-2">&</span>[<span class="number">10</span>, <span class="number">50</span>]), <span class="prelude-val">None</span>);
|
||
|
||
<span class="kw">let</span> <span class="ident">prefix</span> : <span class="kw-2">&</span><span class="ident">str</span> <span class="op">=</span> <span class="string">"he"</span>;
|
||
<span class="macro">assert_eq!</span>(<span class="string">b"hello"</span>.<span class="ident">strip_prefix</span>(<span class="ident">prefix</span>.<span class="ident">as_bytes</span>()),
|
||
<span class="prelude-val">Some</span>(<span class="string">b"llo"</span>.<span class="ident">as_ref</span>()));</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.strip_suffix" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.51.0">1.51.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2285-2287">source</a></span><a href="#method.strip_suffix" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.strip_suffix" class="fnname">strip_suffix</a><P>(&self, suffix: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>P) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[T]</a>> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/slice/trait.SlicePattern.html" title="trait core::slice::SlicePattern">SlicePattern</a><Item = T> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><T>, </span></h4></section></summary><div class="docblock"><p>Returns a subslice with the suffix removed.</p>
|
||
<p>If the slice ends with <code>suffix</code>, returns the subslice before the suffix, wrapped in <code>Some</code>.
|
||
If <code>suffix</code> is empty, simply returns the original slice.</p>
|
||
<p>If the slice does not end with <code>suffix</code>, returns <code>None</code>.</p>
|
||
<h5 id="examples-44"><a href="#examples-44">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&</span>[<span class="number">10</span>, <span class="number">40</span>, <span class="number">30</span>];
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>.<span class="ident">strip_suffix</span>(<span class="kw-2">&</span>[<span class="number">30</span>]), <span class="prelude-val">Some</span>(<span class="kw-2">&</span>[<span class="number">10</span>, <span class="number">40</span>][..]));
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>.<span class="ident">strip_suffix</span>(<span class="kw-2">&</span>[<span class="number">40</span>, <span class="number">30</span>]), <span class="prelude-val">Some</span>(<span class="kw-2">&</span>[<span class="number">10</span>][..]));
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>.<span class="ident">strip_suffix</span>(<span class="kw-2">&</span>[<span class="number">50</span>]), <span class="prelude-val">None</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>.<span class="ident">strip_suffix</span>(<span class="kw-2">&</span>[<span class="number">50</span>, <span class="number">30</span>]), <span class="prelude-val">None</span>);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.binary_search" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2344-2346">source</a></span><a href="#method.binary_search" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.binary_search" class="fnname">binary_search</a>(&self, x: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>T) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>, </span></h4></section></summary><div class="docblock"><p>Binary searches this sorted slice for a given element.</p>
|
||
<p>If the value is found then <a href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html#variant.Ok" title="Result::Ok"><code>Result::Ok</code></a> is returned, containing the
|
||
index of the matching element. If there are multiple matches, then any
|
||
one of the matches could be returned. The index is chosen
|
||
deterministically, but is subject to change in future versions of Rust.
|
||
If the value is not found then <a href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html#variant.Err" title="Result::Err"><code>Result::Err</code></a> is returned, containing
|
||
the index where a matching element could be inserted while maintaining
|
||
sorted order.</p>
|
||
<p>See also <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.binary_search_by"><code>binary_search_by</code></a>, <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.binary_search_by_key"><code>binary_search_by_key</code></a>, and <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.partition_point"><code>partition_point</code></a>.</p>
|
||
<h5 id="examples-45"><a href="#examples-45">Examples</a></h5>
|
||
<p>Looks up a series of four elements. The first is found, with a
|
||
uniquely determined position; the second and third are not
|
||
found; the fourth could match any position in <code>[1, 4]</code>.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> [<span class="number">0</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">8</span>, <span class="number">13</span>, <span class="number">21</span>, <span class="number">34</span>, <span class="number">55</span>];
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">binary_search</span>(<span class="kw-2">&</span><span class="number">13</span>), <span class="prelude-val">Ok</span>(<span class="number">9</span>));
|
||
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">binary_search</span>(<span class="kw-2">&</span><span class="number">4</span>), <span class="prelude-val">Err</span>(<span class="number">7</span>));
|
||
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">binary_search</span>(<span class="kw-2">&</span><span class="number">100</span>), <span class="prelude-val">Err</span>(<span class="number">13</span>));
|
||
<span class="kw">let</span> <span class="ident">r</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">binary_search</span>(<span class="kw-2">&</span><span class="number">1</span>);
|
||
<span class="macro">assert!</span>(<span class="kw">match</span> <span class="ident">r</span> { <span class="prelude-val">Ok</span>(<span class="number">1</span>..<span class="op">=</span><span class="number">4</span>) => <span class="bool-val">true</span>, <span class="kw">_</span> => <span class="bool-val">false</span>, });</code></pre></div>
|
||
<p>If you want to insert an item to a sorted vector, while maintaining
|
||
sort order:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">s</span> <span class="op">=</span> <span class="macro">vec!</span>[<span class="number">0</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">8</span>, <span class="number">13</span>, <span class="number">21</span>, <span class="number">34</span>, <span class="number">55</span>];
|
||
<span class="kw">let</span> <span class="ident">num</span> <span class="op">=</span> <span class="number">42</span>;
|
||
<span class="kw">let</span> <span class="ident">idx</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">binary_search</span>(<span class="kw-2">&</span><span class="ident">num</span>).<span class="ident">unwrap_or_else</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span>);
|
||
<span class="ident">s</span>.<span class="ident">insert</span>(<span class="ident">idx</span>, <span class="ident">num</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">s</span>, [<span class="number">0</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">8</span>, <span class="number">13</span>, <span class="number">21</span>, <span class="number">34</span>, <span class="number">42</span>, <span class="number">55</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.binary_search_by" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2393-2395">source</a></span><a href="#method.binary_search_by" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.binary_search_by" class="fnname">binary_search_by</a><'a, F>(&'a self, f: F) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&'a </a>T) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>, </span></h4></section></summary><div class="docblock"><p>Binary searches this sorted slice with a comparator function.</p>
|
||
<p>The comparator function should implement an order consistent
|
||
with the sort order of the underlying slice, returning an
|
||
order code that indicates whether its argument is <code>Less</code>,
|
||
<code>Equal</code> or <code>Greater</code> the desired target.</p>
|
||
<p>If the value is found then <a href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html#variant.Ok" title="Result::Ok"><code>Result::Ok</code></a> is returned, containing the
|
||
index of the matching element. If there are multiple matches, then any
|
||
one of the matches could be returned. The index is chosen
|
||
deterministically, but is subject to change in future versions of Rust.
|
||
If the value is not found then <a href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html#variant.Err" title="Result::Err"><code>Result::Err</code></a> is returned, containing
|
||
the index where a matching element could be inserted while maintaining
|
||
sorted order.</p>
|
||
<p>See also <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.binary_search"><code>binary_search</code></a>, <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.binary_search_by_key"><code>binary_search_by_key</code></a>, and <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.partition_point"><code>partition_point</code></a>.</p>
|
||
<h5 id="examples-46"><a href="#examples-46">Examples</a></h5>
|
||
<p>Looks up a series of four elements. The first is found, with a
|
||
uniquely determined position; the second and third are not
|
||
found; the fourth could match any position in <code>[1, 4]</code>.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> [<span class="number">0</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">8</span>, <span class="number">13</span>, <span class="number">21</span>, <span class="number">34</span>, <span class="number">55</span>];
|
||
|
||
<span class="kw">let</span> <span class="ident">seek</span> <span class="op">=</span> <span class="number">13</span>;
|
||
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">binary_search_by</span>(<span class="op">|</span><span class="ident">probe</span><span class="op">|</span> <span class="ident">probe</span>.<span class="ident">cmp</span>(<span class="kw-2">&</span><span class="ident">seek</span>)), <span class="prelude-val">Ok</span>(<span class="number">9</span>));
|
||
<span class="kw">let</span> <span class="ident">seek</span> <span class="op">=</span> <span class="number">4</span>;
|
||
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">binary_search_by</span>(<span class="op">|</span><span class="ident">probe</span><span class="op">|</span> <span class="ident">probe</span>.<span class="ident">cmp</span>(<span class="kw-2">&</span><span class="ident">seek</span>)), <span class="prelude-val">Err</span>(<span class="number">7</span>));
|
||
<span class="kw">let</span> <span class="ident">seek</span> <span class="op">=</span> <span class="number">100</span>;
|
||
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">binary_search_by</span>(<span class="op">|</span><span class="ident">probe</span><span class="op">|</span> <span class="ident">probe</span>.<span class="ident">cmp</span>(<span class="kw-2">&</span><span class="ident">seek</span>)), <span class="prelude-val">Err</span>(<span class="number">13</span>));
|
||
<span class="kw">let</span> <span class="ident">seek</span> <span class="op">=</span> <span class="number">1</span>;
|
||
<span class="kw">let</span> <span class="ident">r</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">binary_search_by</span>(<span class="op">|</span><span class="ident">probe</span><span class="op">|</span> <span class="ident">probe</span>.<span class="ident">cmp</span>(<span class="kw-2">&</span><span class="ident">seek</span>));
|
||
<span class="macro">assert!</span>(<span class="kw">match</span> <span class="ident">r</span> { <span class="prelude-val">Ok</span>(<span class="number">1</span>..<span class="op">=</span><span class="number">4</span>) => <span class="bool-val">true</span>, <span class="kw">_</span> => <span class="bool-val">false</span>, });</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.binary_search_by_key" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.10.0">1.10.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2471-2474">source</a></span><a href="#method.binary_search_by_key" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.binary_search_by_key" class="fnname">binary_search_by_key</a><'a, B, F>(<br> &'a self, <br> b: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>B, <br> f: F<br>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&'a </a>T) -> B,<br> B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>, </span></h4></section></summary><div class="docblock"><p>Binary searches this sorted slice with a key extraction function.</p>
|
||
<p>Assumes that the slice is sorted by the key, for instance with
|
||
<a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.sort_by_key"><code>sort_by_key</code></a> using the same key extraction function.</p>
|
||
<p>If the value is found then <a href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html#variant.Ok" title="Result::Ok"><code>Result::Ok</code></a> is returned, containing the
|
||
index of the matching element. If there are multiple matches, then any
|
||
one of the matches could be returned. The index is chosen
|
||
deterministically, but is subject to change in future versions of Rust.
|
||
If the value is not found then <a href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html#variant.Err" title="Result::Err"><code>Result::Err</code></a> is returned, containing
|
||
the index where a matching element could be inserted while maintaining
|
||
sorted order.</p>
|
||
<p>See also <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.binary_search"><code>binary_search</code></a>, <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.binary_search_by"><code>binary_search_by</code></a>, and <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.partition_point"><code>partition_point</code></a>.</p>
|
||
<h5 id="examples-47"><a href="#examples-47">Examples</a></h5>
|
||
<p>Looks up a series of four elements in a slice of pairs sorted by
|
||
their second elements. The first is found, with a uniquely
|
||
determined position; the second and third are not found; the
|
||
fourth could match any position in <code>[1, 4]</code>.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> [(<span class="number">0</span>, <span class="number">0</span>), (<span class="number">2</span>, <span class="number">1</span>), (<span class="number">4</span>, <span class="number">1</span>), (<span class="number">5</span>, <span class="number">1</span>), (<span class="number">3</span>, <span class="number">1</span>),
|
||
(<span class="number">1</span>, <span class="number">2</span>), (<span class="number">2</span>, <span class="number">3</span>), (<span class="number">4</span>, <span class="number">5</span>), (<span class="number">5</span>, <span class="number">8</span>), (<span class="number">3</span>, <span class="number">13</span>),
|
||
(<span class="number">1</span>, <span class="number">21</span>), (<span class="number">2</span>, <span class="number">34</span>), (<span class="number">4</span>, <span class="number">55</span>)];
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">binary_search_by_key</span>(<span class="kw-2">&</span><span class="number">13</span>, <span class="op">|</span><span class="kw-2">&</span>(<span class="ident">a</span>, <span class="ident">b</span>)<span class="op">|</span> <span class="ident">b</span>), <span class="prelude-val">Ok</span>(<span class="number">9</span>));
|
||
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">binary_search_by_key</span>(<span class="kw-2">&</span><span class="number">4</span>, <span class="op">|</span><span class="kw-2">&</span>(<span class="ident">a</span>, <span class="ident">b</span>)<span class="op">|</span> <span class="ident">b</span>), <span class="prelude-val">Err</span>(<span class="number">7</span>));
|
||
<span class="macro">assert_eq!</span>(<span class="ident">s</span>.<span class="ident">binary_search_by_key</span>(<span class="kw-2">&</span><span class="number">100</span>, <span class="op">|</span><span class="kw-2">&</span>(<span class="ident">a</span>, <span class="ident">b</span>)<span class="op">|</span> <span class="ident">b</span>), <span class="prelude-val">Err</span>(<span class="number">13</span>));
|
||
<span class="kw">let</span> <span class="ident">r</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">binary_search_by_key</span>(<span class="kw-2">&</span><span class="number">1</span>, <span class="op">|</span><span class="kw-2">&</span>(<span class="ident">a</span>, <span class="ident">b</span>)<span class="op">|</span> <span class="ident">b</span>);
|
||
<span class="macro">assert!</span>(<span class="kw">match</span> <span class="ident">r</span> { <span class="prelude-val">Ok</span>(<span class="number">1</span>..<span class="op">=</span><span class="number">4</span>) => <span class="bool-val">true</span>, <span class="kw">_</span> => <span class="bool-val">false</span>, });</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.align_to" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.30.0">1.30.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#3429">source</a></span><a href="#method.align_to" class="anchor"></a><h4 class="code-header">pub unsafe fn <a href="#method.align_to" class="fnname">align_to</a><U>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[T]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[U]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.tuple.html">)</a></h4></section></summary><div class="docblock"><p>Transmute the slice to a slice of another type, ensuring alignment of the types is
|
||
maintained.</p>
|
||
<p>This method splits the slice into three distinct slices: prefix, correctly aligned middle
|
||
slice of a new type, and the suffix slice. The method may make the middle slice the greatest
|
||
length possible for a given type and input slice, but only your algorithm’s performance
|
||
should depend on that, not its correctness. It is permissible for all of the input data to
|
||
be returned as the prefix or suffix slice.</p>
|
||
<p>This method has no purpose when either input element <code>T</code> or output element <code>U</code> are
|
||
zero-sized and will return the original slice without splitting anything.</p>
|
||
<h5 id="safety-3"><a href="#safety-3">Safety</a></h5>
|
||
<p>This method is essentially a <code>transmute</code> with respect to the elements in the returned
|
||
middle slice, so all the usual caveats pertaining to <code>transmute::<T, U></code> also apply here.</p>
|
||
<h5 id="examples-48"><a href="#examples-48">Examples</a></h5>
|
||
<p>Basic usage:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">unsafe</span> {
|
||
<span class="kw">let</span> <span class="ident">bytes</span>: [<span class="ident">u8</span>; <span class="number">7</span>] <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">7</span>];
|
||
<span class="kw">let</span> (<span class="ident">prefix</span>, <span class="ident">shorts</span>, <span class="ident">suffix</span>) <span class="op">=</span> <span class="ident">bytes</span>.<span class="ident">align_to</span>::<span class="op"><</span><span class="ident">u16</span><span class="op">></span>();
|
||
<span class="comment">// less_efficient_algorithm_for_bytes(prefix);</span>
|
||
<span class="comment">// more_efficient_algorithm_for_aligned_shorts(shorts);</span>
|
||
<span class="comment">// less_efficient_algorithm_for_bytes(suffix);</span>
|
||
}</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_simd" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#3584-3588">source</a></span><a href="#method.as_simd" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.as_simd" class="fnname">as_simd</a><const LANES: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[T]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[</a><a class="struct" href="https://doc.rust-lang.org/nightly/core/core_simd/vector/struct.Simd.html" title="struct core::core_simd::vector::Simd">Simd</a><T, LANES><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">&[T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/core_simd/vector/trait.SimdElement.html" title="trait core::core_simd::vector::SimdElement">SimdElement</a>,<br> <a class="struct" href="https://doc.rust-lang.org/nightly/core/core_simd/vector/struct.Simd.html" title="struct core::core_simd::vector::Simd">Simd</a><T, LANES>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.array.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.array.html">; LANES]</a>>,<br> <a class="struct" href="https://doc.rust-lang.org/nightly/core/core_simd/lane_count/struct.LaneCount.html" title="struct core::core_simd::lane_count::LaneCount">LaneCount</a><LANES>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/core_simd/lane_count/trait.SupportedLaneCount.html" title="trait core::core_simd::lane_count::SupportedLaneCount">SupportedLaneCount</a>, </span></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>portable_simd</code>)</div></span></summary><div class="docblock"><p>Split a slice into a prefix, a middle of aligned SIMD types, and a suffix.</p>
|
||
<p>This is a safe wrapper around <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.align_to" title="slice::align_to"><code>slice::align_to</code></a>, so has the same weak
|
||
postconditions as that method. You’re only assured that
|
||
<code>self.len() == prefix.len() + middle.len() * LANES + suffix.len()</code>.</p>
|
||
<p>Notably, all of the following are possible:</p>
|
||
<ul>
|
||
<li><code>prefix.len() >= LANES</code>.</li>
|
||
<li><code>middle.is_empty()</code> despite <code>self.len() >= 3 * LANES</code>.</li>
|
||
<li><code>suffix.len() >= LANES</code>.</li>
|
||
</ul>
|
||
<p>That said, this is a safe method, so if you’re only writing safe code,
|
||
then this can at most cause incorrect logic, not unsoundness.</p>
|
||
<h5 id="panics-13"><a href="#panics-13">Panics</a></h5>
|
||
<p>This will panic if the size of the SIMD type is different from
|
||
<code>LANES</code> times that of the scalar.</p>
|
||
<p>At the time of writing, the trait restrictions on <code>Simd<T, LANES></code> keeps
|
||
that from ever happening, as only power-of-two numbers of lanes are
|
||
supported. It’s possible that, in the future, those restrictions might
|
||
be lifted in a way that would make it possible to see panics from this
|
||
method for something like <code>LANES == 3</code>.</p>
|
||
<h5 id="examples-49"><a href="#examples-49">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">portable_simd</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="ident">short</span> <span class="op">=</span> <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
<span class="kw">let</span> (<span class="ident">prefix</span>, <span class="ident">middle</span>, <span class="ident">suffix</span>) <span class="op">=</span> <span class="ident">short</span>.<span class="ident">as_simd</span>::<span class="op"><</span><span class="number">4</span><span class="op">></span>();
|
||
<span class="macro">assert_eq!</span>(<span class="ident">middle</span>, []); <span class="comment">// Not enough elements for anything in the middle</span>
|
||
|
||
<span class="comment">// They might be split in any possible way between prefix and suffix</span>
|
||
<span class="kw">let</span> <span class="ident">it</span> <span class="op">=</span> <span class="ident">prefix</span>.<span class="ident">iter</span>().<span class="ident">chain</span>(<span class="ident">suffix</span>).<span class="ident">copied</span>();
|
||
<span class="macro">assert_eq!</span>(<span class="ident">it</span>.<span class="ident">collect</span>::<span class="op"><</span><span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span><span class="op">></span>(), <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]);
|
||
|
||
<span class="kw">fn</span> <span class="ident">basic_simd_sum</span>(<span class="ident">x</span>: <span class="kw-2">&</span>[<span class="ident">f32</span>]) -> <span class="ident">f32</span> {
|
||
<span class="kw">use</span> <span class="ident">std::ops::Add</span>;
|
||
<span class="kw">use</span> <span class="ident">std::simd::f32x4</span>;
|
||
<span class="kw">let</span> (<span class="ident">prefix</span>, <span class="ident">middle</span>, <span class="ident">suffix</span>) <span class="op">=</span> <span class="ident">x</span>.<span class="ident">as_simd</span>();
|
||
<span class="kw">let</span> <span class="ident">sums</span> <span class="op">=</span> <span class="ident">f32x4::from_array</span>([
|
||
<span class="ident">prefix</span>.<span class="ident">iter</span>().<span class="ident">copied</span>().<span class="ident">sum</span>(),
|
||
<span class="number">0.0</span>,
|
||
<span class="number">0.0</span>,
|
||
<span class="ident">suffix</span>.<span class="ident">iter</span>().<span class="ident">copied</span>().<span class="ident">sum</span>(),
|
||
]);
|
||
<span class="kw">let</span> <span class="ident">sums</span> <span class="op">=</span> <span class="ident">middle</span>.<span class="ident">iter</span>().<span class="ident">copied</span>().<span class="ident">fold</span>(<span class="ident">sums</span>, <span class="ident">f32x4::add</span>);
|
||
<span class="ident">sums</span>.<span class="ident">reduce_sum</span>()
|
||
}
|
||
|
||
<span class="kw">let</span> <span class="ident">numbers</span>: <span class="ident">Vec</span><span class="op"><</span><span class="ident">f32</span><span class="op">></span> <span class="op">=</span> (<span class="number">1</span>..<span class="number">101</span>).<span class="ident">map</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="kw">as</span> <span class="kw">_</span>).<span class="ident">collect</span>();
|
||
<span class="macro">assert_eq!</span>(<span class="ident">basic_simd_sum</span>(<span class="kw-2">&</span><span class="ident">numbers</span>[<span class="number">1</span>..<span class="number">99</span>]), <span class="number">4949.0</span>);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.is_sorted" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#3668-3670">source</a></span><a href="#method.is_sorted" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.is_sorted" class="fnname">is_sorted</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a><T>, </span></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>is_sorted</code>)</div></span></summary><div class="docblock"><p>Checks if the elements of this slice are sorted.</p>
|
||
<p>That is, for each element <code>a</code> and its following element <code>b</code>, <code>a <= b</code> must hold. If the
|
||
slice yields exactly zero or one element, <code>true</code> is returned.</p>
|
||
<p>Note that if <code>Self::Item</code> is only <code>PartialOrd</code>, but not <code>Ord</code>, the above definition
|
||
implies that this function returns <code>false</code> if any two consecutive items are not
|
||
comparable.</p>
|
||
<h5 id="examples-50"><a href="#examples-50">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">is_sorted</span>)]</span>
|
||
<span class="kw">let</span> <span class="ident">empty</span>: [<span class="ident">i32</span>; <span class="number">0</span>] <span class="op">=</span> [];
|
||
|
||
<span class="macro">assert!</span>([<span class="number">1</span>, <span class="number">2</span>, <span class="number">2</span>, <span class="number">9</span>].<span class="ident">is_sorted</span>());
|
||
<span class="macro">assert!</span>(<span class="op">!</span>[<span class="number">1</span>, <span class="number">3</span>, <span class="number">2</span>, <span class="number">4</span>].<span class="ident">is_sorted</span>());
|
||
<span class="macro">assert!</span>([<span class="number">0</span>].<span class="ident">is_sorted</span>());
|
||
<span class="macro">assert!</span>(<span class="ident">empty</span>.<span class="ident">is_sorted</span>());
|
||
<span class="macro">assert!</span>(<span class="op">!</span>[<span class="number">0.0</span>, <span class="number">1.0</span>, <span class="ident">f32::NAN</span>].<span class="ident">is_sorted</span>());</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.is_sorted_by" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#3684-3686">source</a></span><a href="#method.is_sorted_by" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.is_sorted_by" class="fnname">is_sorted_by</a><F>(&self, compare: F) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>T, <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>T) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="enum" href="https://doc.rust-lang.org/nightly/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>>, </span></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>is_sorted</code>)</div></span></summary><div class="docblock"><p>Checks if the elements of this slice are sorted using the given comparator function.</p>
|
||
<p>Instead of using <code>PartialOrd::partial_cmp</code>, this function uses the given <code>compare</code>
|
||
function to determine the ordering of two elements. Apart from that, it’s equivalent to
|
||
<a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.is_sorted"><code>is_sorted</code></a>; see its documentation for more information.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.is_sorted_by_key" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#3710-3713">source</a></span><a href="#method.is_sorted_by_key" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.is_sorted_by_key" class="fnname">is_sorted_by_key</a><F, K>(&self, f: F) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>T) -> K,<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a><K>, </span></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>is_sorted</code>)</div></span></summary><div class="docblock"><p>Checks if the elements of this slice are sorted using the given key extraction function.</p>
|
||
<p>Instead of comparing the slice’s elements directly, this function compares the keys of the
|
||
elements, as determined by <code>f</code>. Apart from that, it’s equivalent to <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.is_sorted"><code>is_sorted</code></a>; see its
|
||
documentation for more information.</p>
|
||
<h5 id="examples-51"><a href="#examples-51">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">is_sorted</span>)]</span>
|
||
|
||
<span class="macro">assert!</span>([<span class="string">"c"</span>, <span class="string">"bb"</span>, <span class="string">"aaa"</span>].<span class="ident">is_sorted_by_key</span>(<span class="op">|</span><span class="ident">s</span><span class="op">|</span> <span class="ident">s</span>.<span class="ident">len</span>()));
|
||
<span class="macro">assert!</span>(<span class="op">!</span>[<span class="op">-</span><span class="number">2i32</span>, <span class="op">-</span><span class="number">1</span>, <span class="number">0</span>, <span class="number">3</span>].<span class="ident">is_sorted_by_key</span>(<span class="op">|</span><span class="ident">n</span><span class="op">|</span> <span class="ident">n</span>.<span class="ident">abs</span>()));</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.partition_point" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.52.0">1.52.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#3748-3750">source</a></span><a href="#method.partition_point" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.partition_point" class="fnname">partition_point</a><P>(&self, pred: P) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a>, </span></h4></section></summary><div class="docblock"><p>Returns the index of the partition point according to the given predicate
|
||
(the index of the first element of the second partition).</p>
|
||
<p>The slice is assumed to be partitioned according to the given predicate.
|
||
This means that all elements for which the predicate returns true are at the start of the slice
|
||
and all elements for which the predicate returns false are at the end.
|
||
For example, [7, 15, 3, 5, 4, 12, 6] is a partitioned under the predicate x % 2 != 0
|
||
(all odd numbers are at the start, all even at the end).</p>
|
||
<p>If this slice is not partitioned, the returned result is unspecified and meaningless,
|
||
as this method performs a kind of binary search.</p>
|
||
<p>See also <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.binary_search"><code>binary_search</code></a>, <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.binary_search_by"><code>binary_search_by</code></a>, and <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.binary_search_by_key"><code>binary_search_by_key</code></a>.</p>
|
||
<h5 id="examples-52"><a href="#examples-52">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">7</span>];
|
||
<span class="kw">let</span> <span class="ident">i</span> <span class="op">=</span> <span class="ident">v</span>.<span class="ident">partition_point</span>(<span class="op">|</span><span class="kw-2">&</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op"><</span> <span class="number">5</span>);
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">i</span>, <span class="number">4</span>);
|
||
<span class="macro">assert!</span>(<span class="ident">v</span>[..<span class="ident">i</span>].<span class="ident">iter</span>().<span class="ident">all</span>(<span class="op">|</span><span class="kw-2">&</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op"><</span> <span class="number">5</span>));
|
||
<span class="macro">assert!</span>(<span class="ident">v</span>[<span class="ident">i</span>..].<span class="ident">iter</span>().<span class="ident">all</span>(<span class="op">|</span><span class="kw-2">&</span><span class="ident">x</span><span class="op">|</span> <span class="op">!</span>(<span class="ident">x</span> <span class="op"><</span> <span class="number">5</span>)));</code></pre></div>
|
||
</div></details></div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.to_ascii_uppercase" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.23.0">1.23.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#686">source</a></span><a href="#method.to_ascii_uppercase" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.to_ascii_uppercase" class="fnname">to_ascii_uppercase</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.u8.html">u8</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/alloc/struct.Global.html" title="struct alloc::alloc::Global">Global</a>></h4></section></summary><div class="docblock"><p>Returns a vector containing a copy of this slice where each byte
|
||
is mapped to its ASCII upper case equivalent.</p>
|
||
<p>ASCII letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’,
|
||
but non-ASCII letters are unchanged.</p>
|
||
<p>To uppercase the value in-place, use <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.make_ascii_uppercase"><code>make_ascii_uppercase</code></a>.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.to_ascii_lowercase" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.23.0">1.23.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#707">source</a></span><a href="#method.to_ascii_lowercase" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.to_ascii_lowercase" class="fnname">to_ascii_lowercase</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.u8.html">u8</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/alloc/struct.Global.html" title="struct alloc::alloc::Global">Global</a>></h4></section></summary><div class="docblock"><p>Returns a vector containing a copy of this slice where each byte
|
||
is mapped to its ASCII lower case equivalent.</p>
|
||
<p>ASCII letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’,
|
||
but non-ASCII letters are unchanged.</p>
|
||
<p>To lowercase the value in-place, use <a href="https://doc.rust-lang.org/nightly/core/primitive.slice.html#method.make_ascii_lowercase"><code>make_ascii_lowercase</code></a>.</p>
|
||
</div></details></div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.to_vec" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#477-479">source</a></span><a href="#method.to_vec" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.to_vec" class="fnname">to_vec</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><T, <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/alloc/struct.Global.html" title="struct alloc::alloc::Global">Global</a>> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, </span></h4></section></summary><div class="docblock"><p>Copies <code>self</code> into a new <code>Vec</code>.</p>
|
||
<h5 id="examples-53"><a href="#examples-53">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> [<span class="number">10</span>, <span class="number">40</span>, <span class="number">30</span>];
|
||
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">to_vec</span>();
|
||
<span class="comment">// Here, `s` and `x` can be modified independently.</span></code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.to_vec_in" class="method has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#501-503">source</a></span><a href="#method.to_vec_in" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.to_vec_in" class="fnname">to_vec_in</a><A>(&self, alloc: A) -> <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><T, A> <span class="where fmt-newline">where<br> A: <a class="trait" href="https://doc.rust-lang.org/nightly/core/alloc/trait.Allocator.html" title="trait core::alloc::Allocator">Allocator</a>,<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, </span></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>allocator_api</code>)</div></span></summary><div class="docblock"><p>Copies <code>self</code> into a new <code>Vec</code> with an allocator.</p>
|
||
<h5 id="examples-54"><a href="#examples-54">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">allocator_api</span>)]</span>
|
||
|
||
<span class="kw">use</span> <span class="ident">std::alloc::System</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> [<span class="number">10</span>, <span class="number">40</span>, <span class="number">30</span>];
|
||
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="ident">s</span>.<span class="ident">to_vec_in</span>(<span class="ident">System</span>);
|
||
<span class="comment">// Here, `s` and `x` can be modified independently.</span></code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.repeat" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.40.0">1.40.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#554-556">source</a></span><a href="#method.repeat" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.repeat" class="fnname">repeat</a>(&self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><T, <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/alloc/struct.Global.html" title="struct alloc::alloc::Global">Global</a>> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Copy.html" title="trait core::marker::Copy">Copy</a>, </span></h4></section></summary><div class="docblock"><p>Creates a vector by repeating a slice <code>n</code> times.</p>
|
||
<h5 id="panics-14"><a href="#panics-14">Panics</a></h5>
|
||
<p>This function will panic if the capacity would overflow.</p>
|
||
<h5 id="examples-55"><a href="#examples-55">Examples</a></h5>
|
||
<p>Basic usage:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>([<span class="number">1</span>, <span class="number">2</span>].<span class="ident">repeat</span>(<span class="number">3</span>), <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">1</span>, <span class="number">2</span>]);</code></pre></div>
|
||
<p>A panic upon overflow:</p>
|
||
|
||
<div class='information'><div class='tooltip should_panic'>ⓘ</div></div><div class="example-wrap"><pre class="rust rust-example-rendered should_panic"><code><span class="comment">// this will panic at runtime</span>
|
||
<span class="string">b"0123456789abcdef"</span>.<span class="ident">repeat</span>(<span class="ident">usize::MAX</span>);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.concat" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#622-624">source</a></span><a href="#method.concat" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.concat" class="fnname">concat</a><Item>(&self) -> <<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">]</a> as <a class="trait" href="https://doc.rust-lang.org/nightly/alloc/slice/trait.Concat.html" title="trait alloc::slice::Concat">Concat</a><Item>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/alloc/slice/trait.Concat.html#associatedtype.Output" title="type alloc::slice::Concat::Output">Output</a> <span class="where fmt-newline">where<br> Item: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,<br> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">]</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/alloc/slice/trait.Concat.html" title="trait alloc::slice::Concat">Concat</a><Item>, </span></h4></section></summary><div class="docblock"><p>Flattens a slice of <code>T</code> into a single value <code>Self::Output</code>.</p>
|
||
<h5 id="examples-56"><a href="#examples-56">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>([<span class="string">"hello"</span>, <span class="string">"world"</span>].<span class="ident">concat</span>(), <span class="string">"helloworld"</span>);
|
||
<span class="macro">assert_eq!</span>([[<span class="number">1</span>, <span class="number">2</span>], [<span class="number">3</span>, <span class="number">4</span>]].<span class="ident">concat</span>(), [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.join" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.3.0">1.3.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#641-643">source</a></span><a href="#method.join" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.join" class="fnname">join</a><Separator>(<br> &self, <br> sep: Separator<br>) -> <<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">]</a> as <a class="trait" href="https://doc.rust-lang.org/nightly/alloc/slice/trait.Join.html" title="trait alloc::slice::Join">Join</a><Separator>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/alloc/slice/trait.Join.html#associatedtype.Output" title="type alloc::slice::Join::Output">Output</a> <span class="where fmt-newline">where<br> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">]</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/alloc/slice/trait.Join.html" title="trait alloc::slice::Join">Join</a><Separator>, </span></h4></section></summary><div class="docblock"><p>Flattens a slice of <code>T</code> into a single value <code>Self::Output</code>, placing a
|
||
given separator between each.</p>
|
||
<h5 id="examples-57"><a href="#examples-57">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>([<span class="string">"hello"</span>, <span class="string">"world"</span>].<span class="ident">join</span>(<span class="string">" "</span>), <span class="string">"hello world"</span>);
|
||
<span class="macro">assert_eq!</span>([[<span class="number">1</span>, <span class="number">2</span>], [<span class="number">3</span>, <span class="number">4</span>]].<span class="ident">join</span>(<span class="kw-2">&</span><span class="number">0</span>), [<span class="number">1</span>, <span class="number">2</span>, <span class="number">0</span>, <span class="number">3</span>, <span class="number">4</span>]);
|
||
<span class="macro">assert_eq!</span>([[<span class="number">1</span>, <span class="number">2</span>], [<span class="number">3</span>, <span class="number">4</span>]].<span class="ident">join</span>(<span class="kw-2">&</span>[<span class="number">0</span>, <span class="number">0</span>][..]), [<span class="number">1</span>, <span class="number">2</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">3</span>, <span class="number">4</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.connect" class="method has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#661-663">source</a></span><a href="#method.connect" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.connect" class="fnname">connect</a><Separator>(<br> &self, <br> sep: Separator<br>) -> <<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">]</a> as <a class="trait" href="https://doc.rust-lang.org/nightly/alloc/slice/trait.Join.html" title="trait alloc::slice::Join">Join</a><Separator>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/alloc/slice/trait.Join.html#associatedtype.Output" title="type alloc::slice::Join::Output">Output</a> <span class="where fmt-newline">where<br> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">]</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/alloc/slice/trait.Join.html" title="trait alloc::slice::Join">Join</a><Separator>, </span></h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span> Deprecated since 1.3.0: <p>renamed to join</p>
|
||
</div></span></summary><div class="docblock"><p>Flattens a slice of <code>T</code> into a single value <code>Self::Output</code>, placing a
|
||
given separator between each.</p>
|
||
<h5 id="examples-58"><a href="#examples-58">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>([<span class="string">"hello"</span>, <span class="string">"world"</span>].<span class="ident">connect</span>(<span class="string">" "</span>), <span class="string">"hello world"</span>);
|
||
<span class="macro">assert_eq!</span>([[<span class="number">1</span>, <span class="number">2</span>], [<span class="number">3</span>, <span class="number">4</span>]].<span class="ident">connect</span>(<span class="kw-2">&</span><span class="number">0</span>), [<span class="number">1</span>, <span class="number">2</span>, <span class="number">0</span>, <span class="number">3</span>, <span class="number">4</span>]);</code></pre></div>
|
||
</div></details></div></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Deref" class="impl has-srclink"><span class="rightside"><a class="srclink" href="../../src/os/loader.rs.html#30-53">source</a></span><a href="#impl-Deref" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a> for <a class="struct" href="struct.APP_NAMES.html" title="struct os::loader::APP_NAMES">APP_NAMES</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Target" class="type trait-impl has-srclink"><a href="#associatedtype.Target" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html#associatedtype.Target" class="associatedtype">Target</a> = <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><&'static <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.str.html">str</a>></h4></section></summary><div class='docblock'><p>The resulting type after dereferencing.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.deref" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="../../src/os/loader.rs.html#30-53">source</a></span><a href="#method.deref" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html#tymethod.deref" class="fnname">deref</a>(&self) -> &<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><&'static <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.str.html">str</a>></h4></section></summary><div class='docblock'><p>Dereferences the value.</p>
|
||
</div></details></div></details><section id="impl-LazyStatic" class="impl has-srclink"><span class="rightside"><a class="srclink" href="../../src/os/loader.rs.html#30-53">source</a></span><a href="#impl-LazyStatic" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://docs.rs/lazy_static/1.4.0/lazy_static/trait.LazyStatic.html" title="trait lazy_static::LazyStatic">LazyStatic</a> for <a class="struct" href="struct.APP_NAMES.html" title="struct os::loader::APP_NAMES">APP_NAMES</a></h3></section></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><section id="impl-RefUnwindSafe" class="impl has-srclink"><a href="#impl-RefUnwindSafe" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.APP_NAMES.html" title="struct os::loader::APP_NAMES">APP_NAMES</a></h3></section><section id="impl-Send" class="impl has-srclink"><a href="#impl-Send" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.APP_NAMES.html" title="struct os::loader::APP_NAMES">APP_NAMES</a></h3></section><section id="impl-Sync" class="impl has-srclink"><a href="#impl-Sync" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.APP_NAMES.html" title="struct os::loader::APP_NAMES">APP_NAMES</a></h3></section><section id="impl-Unpin" class="impl has-srclink"><a href="#impl-Unpin" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.APP_NAMES.html" title="struct os::loader::APP_NAMES">APP_NAMES</a></h3></section><section id="impl-UnwindSafe" class="impl has-srclink"><a href="#impl-UnwindSafe" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.APP_NAMES.html" title="struct os::loader::APP_NAMES">APP_NAMES</a></h3></section></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Any" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#132-136">source</a></span><a href="#impl-Any" class="anchor"></a><h3 class="code-header in-band">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T <span class="where fmt-newline">where<br> T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#133">source</a></span><a href="#method.type_id" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id" class="fnname">type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'><p>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#209-214">source</a></span><a href="#impl-Borrow%3CT%3E" class="anchor"></a><h3 class="code-header in-band">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><T> for T <span class="where fmt-newline">where<br> T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#211">source</a></span><a href="#method.borrow" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow" class="fnname">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&</a>T</h4></section></summary><div class='docblock'><p>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#218-222">source</a></span><a href="#impl-BorrowMut%3CT%3E" class="anchor"></a><h3 class="code-header in-band">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><T> for T <span class="where fmt-newline">where<br> T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#219">source</a></span><a href="#method.borrow_mut" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fnname">borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.reference.html">&mut </a>T</h4></section></summary><div class='docblock'><p>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-From%3CT%3E" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#557-562">source</a></span><a href="#impl-From%3CT%3E" class="anchor"></a><h3 class="code-header in-band">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for T</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#559">source</a></span><a href="#method.from" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(t: T) -> T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#541-552">source</a></span><a href="#impl-Into%3CU%3E" class="anchor"></a><h3 class="code-header in-band">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><T>, </span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#549">source</a></span><a href="#method.into" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html#tymethod.into" class="fnname">into</a>(self) -> U</h4></section></summary><div class="docblock"><p>Calls <code>U::from(self)</code>.</p>
|
||
<p>That is, this conversion is whatever the implementation of
|
||
<code><a href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="From">From</a><T> for U</code> chooses to do.</p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#598-607">source</a></span><a href="#impl-TryFrom%3CU%3E" class="anchor"></a><h3 class="code-header in-band">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>, </span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error" class="type trait-impl has-srclink"><a href="#associatedtype.Error" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></h4></section></summary><div class='docblock'><p>The type returned in the event of a conversion error.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#604">source</a></span><a href="#method.try_from" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#tymethod.try_from" class="fnname">try_from</a>(value: U) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <T as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'><p>Performs the conversion.</p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E" class="impl has-srclink"><span class="rightside"><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#583-592">source</a></span><a href="#impl-TryInto%3CU%3E" class="anchor"></a><h3 class="code-header in-band">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>, </span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error-1" class="type trait-impl has-srclink"><a href="#associatedtype.Error-1" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></h4></section></summary><div class='docblock'><p>The type returned in the event of a conversion error.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#589">source</a></span><a href="#method.try_into" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#tymethod.try_into" class="fnname">try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, <U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'><p>Performs the conversion.</p>
|
||
</div></details></div></details></div></section><section id="search" class="content hidden"></section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="os" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.62.0-nightly (1f7fb6413 2022-04-10)" ></div>
|
||
</body></html> |