2230 lines
533 KiB
HTML
2230 lines
533 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="A `Vec`-like container that can store a small number of elements inline."><meta name="keywords" content="rust, rustlang, rust-lang, SmallVec"><title>SmallVec in smallvec - 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="sidebar"><div class="sidebar-menu" role="button">☰</div><a class="sidebar-logo" href="../smallvec/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.png" alt="logo"></div>
|
||
</a><h2 class="location">Struct SmallVec</h2><div class="sidebar-elems"><div class="block items"><h3 class="sidebar-title"><a href="#implementations">Methods</a></h3><div class="sidebar-links"><a href="#method.append">append</a><a href="#method.as_mut_ptr">as_mut_ptr</a><a href="#method.as_mut_slice">as_mut_slice</a><a href="#method.as_ptr">as_ptr</a><a href="#method.as_slice">as_slice</a><a href="#method.capacity">capacity</a><a href="#method.clear">clear</a><a href="#method.dedup">dedup</a><a href="#method.dedup_by">dedup_by</a><a href="#method.dedup_by_key">dedup_by_key</a><a href="#method.drain">drain</a><a href="#method.extend_from_slice">extend_from_slice</a><a href="#method.from_buf">from_buf</a><a href="#method.from_buf_and_len">from_buf_and_len</a><a href="#method.from_buf_and_len_unchecked">from_buf_and_len_unchecked</a><a href="#method.from_elem">from_elem</a><a href="#method.from_raw_parts">from_raw_parts</a><a href="#method.from_slice">from_slice</a><a href="#method.from_vec">from_vec</a><a href="#method.grow">grow</a><a href="#method.inline_size">inline_size</a><a href="#method.insert">insert</a><a href="#method.insert_from_slice">insert_from_slice</a><a href="#method.insert_many">insert_many</a><a href="#method.into_boxed_slice">into_boxed_slice</a><a href="#method.into_inner">into_inner</a><a href="#method.into_vec">into_vec</a><a href="#method.is_empty">is_empty</a><a href="#method.len">len</a><a href="#method.new">new</a><a href="#method.pop">pop</a><a href="#method.push">push</a><a href="#method.remove">remove</a><a href="#method.reserve">reserve</a><a href="#method.reserve_exact">reserve_exact</a><a href="#method.resize">resize</a><a href="#method.resize_with">resize_with</a><a href="#method.retain">retain</a><a href="#method.set_len">set_len</a><a href="#method.shrink_to_fit">shrink_to_fit</a><a href="#method.spilled">spilled</a><a href="#method.swap_remove">swap_remove</a><a href="#method.truncate">truncate</a><a href="#method.try_grow">try_grow</a><a href="#method.try_reserve">try_reserve</a><a href="#method.try_reserve_exact">try_reserve_exact</a><a href="#method.with_capacity">with_capacity</a></div><h3 class="sidebar-title"><a href="#deref-methods-%5BA%3A%3AItem%5D">Methods from Deref<Target=[A::Item]></a></h3><div class="sidebar-links"><a href="#method.align_to">align_to</a><a href="#method.align_to_mut">align_to_mut</a><a href="#method.array_chunks">array_chunks</a><a href="#method.array_chunks_mut">array_chunks_mut</a><a href="#method.array_windows">array_windows</a><a href="#method.as_chunks">as_chunks</a><a href="#method.as_chunks_mut">as_chunks_mut</a><a href="#method.as_chunks_unchecked">as_chunks_unchecked</a><a href="#method.as_chunks_unchecked_mut">as_chunks_unchecked_mut</a><a href="#method.as_mut_ptr">as_mut_ptr</a><a href="#method.as_mut_ptr_range">as_mut_ptr_range</a><a href="#method.as_ptr">as_ptr</a><a href="#method.as_ptr_range">as_ptr_range</a><a href="#method.as_rchunks">as_rchunks</a><a href="#method.as_rchunks_mut">as_rchunks_mut</a><a href="#method.as_simd">as_simd</a><a href="#method.as_simd_mut">as_simd_mut</a><a href="#method.binary_search">binary_search</a><a href="#method.binary_search_by">binary_search_by</a><a href="#method.binary_search_by_key">binary_search_by_key</a><a href="#method.chunks">chunks</a><a href="#method.chunks_exact">chunks_exact</a><a href="#method.chunks_exact_mut">chunks_exact_mut</a><a href="#method.chunks_mut">chunks_mut</a><a href="#method.clone_from_slice">clone_from_slice</a><a href="#method.concat">concat</a><a href="#method.connect">connect</a><a href="#method.contains">contains</a><a href="#method.copy_from_slice">copy_from_slice</a><a href="#method.copy_within">copy_within</a><a href="#method.ends_with">ends_with</a><a href="#method.eq_ignore_ascii_case">eq_ignore_ascii_case</a><a href="#method.escape_ascii">escape_ascii</a><a href="#method.fill">fill</a><a href="#method.fill_with">fill_with</a><a href="#method.first">first</a><a href="#method.first_mut">first_mut</a><a href="#method.get">get</a><a href="#method.get_mut">get_mut</a><a href="#method.get_unchecked">get_unchecked</a><a href="#method.get_unchecked_mut">get_unchecked_mut</a><a href="#method.group_by">group_by</a><a href="#method.group_by_mut">group_by_mut</a><a href="#method.is_ascii">is_ascii</a><a href="#method.is_empty">is_empty</a><a href="#method.is_sorted">is_sorted</a><a href="#method.is_sorted_by">is_sorted_by</a><a href="#method.is_sorted_by_key">is_sorted_by_key</a><a href="#method.iter">iter</a><a href="#method.iter_mut">iter_mut</a><a href="#method.join">join</a><a href="#method.last">last</a><a href="#method.last_mut">last_mut</a><a href="#method.len">len</a><a href="#method.make_ascii_lowercase">make_ascii_lowercase</a><a href="#method.make_ascii_uppercase">make_ascii_uppercase</a><a href="#method.partition_at_index">partition_at_index</a><a href="#method.partition_at_index_by">partition_at_index_by</a><a href="#method.partition_at_index_by_key">partition_at_index_by_key</a><a href="#method.partition_dedup">partition_dedup</a><a href="#method.partition_dedup_by">partition_dedup_by</a><a href="#method.partition_dedup_by_key">partition_dedup_by_key</a><a href="#method.partition_point">partition_point</a><a href="#method.rchunks">rchunks</a><a href="#method.rchunks_exact">rchunks_exact</a><a href="#method.rchunks_exact_mut">rchunks_exact_mut</a><a href="#method.rchunks_mut">rchunks_mut</a><a href="#method.repeat">repeat</a><a href="#method.reverse">reverse</a><a href="#method.rotate_left">rotate_left</a><a href="#method.rotate_right">rotate_right</a><a href="#method.rsplit">rsplit</a><a href="#method.rsplit_array_mut">rsplit_array_mut</a><a href="#method.rsplit_array_ref">rsplit_array_ref</a><a href="#method.rsplit_mut">rsplit_mut</a><a href="#method.rsplitn">rsplitn</a><a href="#method.rsplitn_mut">rsplitn_mut</a><a href="#method.select_nth_unstable">select_nth_unstable</a><a href="#method.select_nth_unstable_by">select_nth_unstable_by</a><a href="#method.select_nth_unstable_by_key">select_nth_unstable_by_key</a><a href="#method.sort">sort</a><a href="#method.sort_by">sort_by</a><a href="#method.sort_by_cached_key">sort_by_cached_key</a><a href="#method.sort_by_key">sort_by_key</a><a href="#method.sort_unstable">sort_unstable</a><a href="#method.sort_unstable_by">sort_unstable_by</a><a href="#method.sort_unstable_by_key">sort_unstable_by_key</a><a href="#method.split">split</a><a href="#method.split_array_mut">split_array_mut</a><a href="#method.split_array_ref">split_array_ref</a><a href="#method.split_at">split_at</a><a href="#method.split_at_mut">split_at_mut</a><a href="#method.split_at_mut_unchecked">split_at_mut_unchecked</a><a href="#method.split_at_unchecked">split_at_unchecked</a><a href="#method.split_first">split_first</a><a href="#method.split_first_mut">split_first_mut</a><a href="#method.split_inclusive">split_inclusive</a><a href="#method.split_inclusive_mut">split_inclusive_mut</a><a href="#method.split_last">split_last</a><a href="#method.split_last_mut">split_last_mut</a><a href="#method.split_mut">split_mut</a><a href="#method.splitn">splitn</a><a href="#method.splitn_mut">splitn_mut</a><a href="#method.starts_with">starts_with</a><a href="#method.strip_prefix">strip_prefix</a><a href="#method.strip_suffix">strip_suffix</a><a href="#method.swap">swap</a><a href="#method.swap_unchecked">swap_unchecked</a><a href="#method.swap_with_slice">swap_with_slice</a><a href="#method.take">take</a><a href="#method.take_first">take_first</a><a href="#method.take_first_mut">take_first_mut</a><a href="#method.take_last">take_last</a><a href="#method.take_last_mut">take_last_mut</a><a href="#method.take_mut">take_mut</a><a href="#method.to_ascii_lowercase">to_ascii_lowercase</a><a href="#method.to_ascii_uppercase">to_ascii_uppercase</a><a href="#method.to_vec">to_vec</a><a href="#method.to_vec_in">to_vec_in</a><a href="#method.windows">windows</a></div><h3 class="sidebar-title"><a href="#trait-implementations">Trait Implementations</a></h3><div class="sidebar-links"><a href="#impl-AsMut%3C%5B%3CA%20as%20Array%3E%3A%3AItem%5D%3E">AsMut<[<A as Array>::Item]></a><a href="#impl-AsRef%3C%5B%3CA%20as%20Array%3E%3A%3AItem%5D%3E">AsRef<[<A as Array>::Item]></a><a href="#impl-Borrow%3C%5B%3CA%20as%20Array%3E%3A%3AItem%5D%3E">Borrow<[<A as Array>::Item]></a><a href="#impl-BorrowMut%3C%5B%3CA%20as%20Array%3E%3A%3AItem%5D%3E">BorrowMut<[<A as Array>::Item]></a><a href="#impl-Clone">Clone</a><a href="#impl-Debug">Debug</a><a href="#impl-Default">Default</a><a href="#impl-Deref">Deref</a><a href="#impl-DerefMut">DerefMut</a><a href="#impl-Drop">Drop</a><a href="#impl-Eq">Eq</a><a href="#impl-Extend%3C%3CA%20as%20Array%3E%3A%3AItem%3E">Extend<<A as Array>::Item></a><a href="#impl-From%3C%26%27a%20%5B%3CA%20as%20Array%3E%3A%3AItem%5D%3E">From<&'a [<A as Array>::Item]></a><a href="#impl-From%3CA%3E">From<A></a><a href="#impl-From%3CVec%3C%3CA%20as%20Array%3E%3A%3AItem%2C%20Global%3E%3E">From<Vec<<A as Array>::Item, Global>></a><a href="#impl-FromIterator%3C%3CA%20as%20Array%3E%3A%3AItem%3E">FromIterator<<A as Array>::Item></a><a href="#impl-Hash">Hash</a><a href="#impl-Index%3CI%3E">Index<I></a><a href="#impl-IndexMut%3CI%3E">IndexMut<I></a><a href="#impl-IntoIterator">IntoIterator</a><a href="#impl-Ord">Ord</a><a href="#impl-PartialEq%3CSmallVec%3CB%3E%3E">PartialEq<SmallVec<B>></a><a href="#impl-PartialOrd%3CSmallVec%3CA%3E%3E">PartialOrd<SmallVec<A>></a><a href="#impl-Send">Send</a></div><h3 class="sidebar-title"><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><div class="sidebar-links"><a href="#impl-RefUnwindSafe">RefUnwindSafe</a><a href="#impl-Sync">Sync</a><a href="#impl-Unpin">Unpin</a><a href="#impl-UnwindSafe">UnwindSafe</a></div><h3 class="sidebar-title"><a href="#blanket-implementations">Blanket Implementations</a></h3><div class="sidebar-links"><a href="#impl-Any">Any</a><a href="#impl-Borrow%3CT%3E">Borrow<T></a><a href="#impl-BorrowMut%3CT%3E">BorrowMut<T></a><a href="#impl-From%3C!%3E">From<!></a><a href="#impl-From%3CT%3E">From<T></a><a href="#impl-Into%3CU%3E">Into<U></a><a href="#impl-ToOwned">ToOwned</a><a href="#impl-TryFrom%3CU%3E">TryFrom<U></a><a href="#impl-TryInto%3CU%3E">TryInto<U></a></div></div><h2 class="location">Other items in<br><a href="index.html">smallvec</a></h2><div id="sidebar-vars" data-name="SmallVec" 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="../smallvec/index.html"><img class="rust-logo" src="../rust-logo.png" alt="logo"></a><nav class="sub"><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"><img width="18" height="18" alt="Pick another theme!" src="../brush.svg"></button><div id="theme-choices" role="menu"></div></div><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" id="help-button" title="help">?</button><a id="settings-menu" href="../settings.html" title="settings"><img width="18" height="18" alt="Change settings" src="../wheel.svg"></a></div></form></nav></div><section id="main-content" class="content"><h1 class="fqn"><span class="in-band">Struct <a href="index.html">smallvec</a>::<wbr><a class="struct" href="#">SmallVec</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><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span><a class="srclink" href="../src/smallvec/lib.rs.html#547-553" title="goto source code">[src]</a></span></h1><div class="docblock item-decl"><pre class="rust struct"><code>pub struct SmallVec<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> { /* fields omitted */ }</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A <code>Vec</code>-like container that can store a small number of elements inline.</p>
|
||
<p><code>SmallVec</code> acts like a vector, but can store a limited amount of data inline within the
|
||
<code>SmallVec</code> struct rather than in a separate allocation. If the data exceeds this limit, the
|
||
<code>SmallVec</code> will “spill” its data onto the heap, allocating a new buffer to hold it.</p>
|
||
<p>The amount of data that a <code>SmallVec</code> can store inline depends on its backing store. The backing
|
||
store can be any type that implements the <code>Array</code> trait; usually it is a small fixed-sized
|
||
array. For example a <code>SmallVec<[u64; 8]></code> can hold up to eight 64-bit integers inline.</p>
|
||
<h3 id="example" class="section-header"><a href="#example">Example</a></h3>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">smallvec::SmallVec</span>;
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> <span class="ident">SmallVec</span>::<span class="op"><</span>[<span class="ident">u8</span>; <span class="number">4</span>]<span class="op">></span><span class="ident">::new</span>(); <span class="comment">// initialize an empty vector</span>
|
||
|
||
<span class="comment">// The vector can hold up to 4 items without spilling onto the heap.</span>
|
||
<span class="ident">v</span>.<span class="ident">extend</span>(<span class="number">0</span>..<span class="number">4</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>.<span class="ident">len</span>(), <span class="number">4</span>);
|
||
<span class="macro">assert!</span>(<span class="op">!</span><span class="ident">v</span>.<span class="ident">spilled</span>());
|
||
|
||
<span class="comment">// Pushing another element will force the buffer to spill:</span>
|
||
<span class="ident">v</span>.<span class="ident">push</span>(<span class="number">4</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>.<span class="ident">len</span>(), <span class="number">5</span>);
|
||
<span class="macro">assert!</span>(<span class="ident">v</span>.<span class="ident">spilled</span>());</code></pre></div>
|
||
</div></details><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#555-1405" title="goto source code">[src]</a></div><a href="#impl" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.new" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#558-569" title="goto source code">[src]</a></div><a href="#method.new" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.new" class="fnname">new</a>() -> <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h4></div></summary><div class="docblock"><p>Construct an empty vector</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.with_capacity" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#585-589" title="goto source code">[src]</a></div><a href="#method.with_capacity" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.with_capacity" class="fnname">with_capacity</a>(n: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>) -> Self</h4></div></summary><div class="docblock"><p>Construct an empty vector with enough capacity pre-allocated to store at least <code>n</code>
|
||
elements.</p>
|
||
<p>Will create a heap allocation only if <code>n</code> is larger than the inline capacity.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code>
|
||
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">SmallVec</span><span class="op"><</span>[<span class="ident">u8</span>; <span class="number">3</span>]<span class="op">></span> <span class="op">=</span> <span class="ident">SmallVec::with_capacity</span>(<span class="number">100</span>);
|
||
|
||
<span class="macro">assert!</span>(<span class="ident">v</span>.<span class="ident">is_empty</span>());
|
||
<span class="macro">assert!</span>(<span class="ident">v</span>.<span class="ident">capacity</span>() <span class="op">></span><span class="op">=</span> <span class="number">100</span>);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.from_vec" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#604-626" title="goto source code">[src]</a></div><a href="#method.from_vec" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.from_vec" class="fnname">from_vec</a>(vec: <a class="struct" href="https://doc.rust-lang.org/1.59.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>>) -> <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h4></div></summary><div class="docblock"><p>Construct a new <code>SmallVec</code> from a <code>Vec<A::Item></code>.</p>
|
||
<p>Elements will be copied to the inline buffer if vec.capacity() <= Self::inline_capacity().</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">smallvec::SmallVec</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">vec</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">4</span>, <span class="number">5</span>];
|
||
<span class="kw">let</span> <span class="ident">small_vec</span>: <span class="ident">SmallVec</span><span class="op"><</span>[<span class="kw">_</span>; <span class="number">3</span>]<span class="op">></span> <span class="op">=</span> <span class="ident">SmallVec::from_vec</span>(<span class="ident">vec</span>);
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span><span class="kw-2">*</span><span class="ident">small_vec</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>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.from_buf" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#640-645" title="goto source code">[src]</a></div><a href="#method.from_buf" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.from_buf" class="fnname">from_buf</a>(buf: A) -> <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h4></div></summary><div class="docblock"><p>Constructs a new <code>SmallVec</code> on the stack from an <code>A</code> without
|
||
copying elements.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">smallvec::SmallVec</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">buf</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="kw">let</span> <span class="ident">small_vec</span>: <span class="ident">SmallVec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">SmallVec::from_buf</span>(<span class="ident">buf</span>);
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span><span class="kw-2">*</span><span class="ident">small_vec</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>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.from_buf_and_len" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#660-663" title="goto source code">[src]</a></div><a href="#method.from_buf_and_len" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.from_buf_and_len" class="fnname">from_buf_and_len</a>(buf: A, len: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>) -> <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h4></div></summary><div class="docblock"><p>Constructs a new <code>SmallVec</code> on the stack from an <code>A</code> without
|
||
copying elements. Also sets the length, which must be less or
|
||
equal to the size of <code>buf</code>.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">smallvec::SmallVec</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">buf</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">0</span>, <span class="number">0</span>, <span class="number">0</span>];
|
||
<span class="kw">let</span> <span class="ident">small_vec</span>: <span class="ident">SmallVec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">SmallVec::from_buf_and_len</span>(<span class="ident">buf</span>, <span class="number">5</span>);
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span><span class="kw-2">*</span><span class="ident">small_vec</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>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.from_buf_and_len_unchecked" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#681-686" title="goto source code">[src]</a></div><a href="#method.from_buf_and_len_unchecked" class="anchor"></a><h4 class="code-header">pub unsafe fn <a href="#method.from_buf_and_len_unchecked" class="fnname">from_buf_and_len_unchecked</a>(<br> buf: <a class="union" href="https://doc.rust-lang.org/1.59.0/core/mem/maybe_uninit/union.MaybeUninit.html" title="union core::mem::maybe_uninit::MaybeUninit">MaybeUninit</a><A>, <br> len: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a><br>) -> <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h4></div></summary><div class="docblock"><p>Constructs a new <code>SmallVec</code> on the stack from an <code>A</code> without
|
||
copying elements. Also sets the length. The user is responsible
|
||
for ensuring that <code>len <= A::size()</code>.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">smallvec::SmallVec</span>;
|
||
<span class="kw">use</span> <span class="ident">std::mem::MaybeUninit</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">buf</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">0</span>, <span class="number">0</span>, <span class="number">0</span>];
|
||
<span class="kw">let</span> <span class="ident">small_vec</span>: <span class="ident">SmallVec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="kw">unsafe</span> {
|
||
<span class="ident">SmallVec::from_buf_and_len_unchecked</span>(<span class="ident">MaybeUninit::new</span>(<span class="ident">buf</span>), <span class="number">5</span>)
|
||
};
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span><span class="kw-2">*</span><span class="ident">small_vec</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>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.set_len" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#693-696" title="goto source code">[src]</a></div><a href="#method.set_len" class="anchor"></a><h4 class="code-header">pub unsafe fn <a href="#method.set_len" class="fnname">set_len</a>(&mut self, new_len: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>)</h4></div></summary><div class="docblock"><p>Sets the length of a vector.</p>
|
||
<p>This will explicitly set the size of the vector, without actually
|
||
modifying its buffers, so it is up to the caller to ensure that the
|
||
vector is actually the specified size.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.inline_size" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#720-722" title="goto source code">[src]</a></div><a href="#method.inline_size" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.inline_size" class="fnname">inline_size</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a></h4></div></summary><div class="docblock"><p>The maximum number of elements this vector can hold inline</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.len" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#726-728" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a></h4></div></summary><div class="docblock"><p>The number of elements stored in the vector</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.is_empty" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#732-734" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.bool.html">bool</a></h4></div></summary><div class="docblock"><p>Returns <code>true</code> if the vector is empty</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.capacity" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#738-740" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a></h4></div></summary><div class="docblock"><p>The number of items the vector can hold without reallocating</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.spilled" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#775-777" title="goto source code">[src]</a></div><a href="#method.spilled" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.spilled" class="fnname">spilled</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a></h4></div></summary><div class="docblock"><p>Returns <code>true</code> if the data has spilled into a separate heap-allocated buffer.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.drain" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#792-825" title="goto source code">[src]</a></div><a href="#method.drain" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.drain" class="fnname">drain</a><R>(&mut self, range: R) -> <a class="struct" href="struct.Drain.html" title="struct smallvec::Drain">Drain</a><'_, A><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><div class="notable">Notable traits for <a class="struct" href="struct.Drain.html" title="struct smallvec::Drain">Drain</a><'a, T></div><code class="content"><span class="where fmt-newline">impl<'a, T: 'a + <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> for <a class="struct" href="struct.Drain.html" title="struct smallvec::Drain">Drain</a><'a, T></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" class="associatedtype">Item</a> = T::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>;</span></code></span></div></span></span> <span class="where fmt-newline">where<br> R: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/range/trait.RangeBounds.html" title="trait core::ops::range::RangeBounds">RangeBounds</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>>, </span></h4></div></summary><div class="docblock"><p>Creates a draining iterator that removes the specified range in the vector
|
||
and yields the removed items.</p>
|
||
<p>Note 1: The element range is removed even if the iterator is only
|
||
partially consumed or not consumed at all.</p>
|
||
<p>Note 2: It is unspecified how many elements are removed from the vector
|
||
if the <code>Drain</code> value is leaked.</p>
|
||
<h5 id="panics" class="section-header"><a href="#panics">Panics</a></h5>
|
||
<p>Panics if the starting point is greater than the end point or if
|
||
the end point is greater than the length of the vector.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.push" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#829-841" title="goto source code">[src]</a></div><a href="#method.push" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.push" class="fnname">push</a>(&mut self, value: A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>)</h4></div></summary><div class="docblock"><p>Append an item to the vector.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.pop" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#845-855" title="goto source code">[src]</a></div><a href="#method.pop" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.pop" class="fnname">pop</a>(&mut self) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>></h4></div></summary><div class="docblock"><p>Remove an item from the end of the vector and return it, or None if empty.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.append" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#869-874" title="goto source code">[src]</a></div><a href="#method.append" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.append" class="fnname">append</a><B>(&mut self, other: &mut <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><B>) <span class="where fmt-newline">where<br> B: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a><Item = A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>>, </span></h4></div></summary><div class="docblock"><p>Moves all the elements of <code>other</code> into <code>self</code>, leaving <code>other</code> empty.</p>
|
||
<h5 id="example-1" class="section-header"><a href="#example-1">Example</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">v0</span>: <span class="ident">SmallVec</span><span class="op"><</span>[<span class="ident">u8</span>; <span class="number">16</span>]<span class="op">></span> <span class="op">=</span> <span class="macro">smallvec!</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">v1</span>: <span class="ident">SmallVec</span><span class="op"><</span>[<span class="ident">u8</span>; <span class="number">32</span>]<span class="op">></span> <span class="op">=</span> <span class="macro">smallvec!</span>[<span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>];
|
||
<span class="ident">v0</span>.<span class="ident">append</span>(<span class="kw-2">&mut</span> <span class="ident">v1</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span><span class="ident">v0</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="kw-2">*</span><span class="ident">v1</span>, []);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.grow" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#880-882" title="goto source code">[src]</a></div><a href="#method.grow" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.grow" class="fnname">grow</a>(&mut self, new_cap: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>)</h4></div></summary><div class="docblock"><p>Re-allocate to set the capacity to <code>max(new_cap, inline_size())</code>.</p>
|
||
<p>Panics if <code>new_cap</code> is less than the vector’s length
|
||
or if the capacity computation overflows <code>usize</code>.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.try_grow" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#887-926" title="goto source code">[src]</a></div><a href="#method.try_grow" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.try_grow" class="fnname">try_grow</a>(&mut self, new_cap: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.unit.html">()</a>, <a class="enum" href="enum.CollectionAllocErr.html" title="enum smallvec::CollectionAllocErr">CollectionAllocErr</a>></h4></div></summary><div class="docblock"><p>Re-allocate to set the capacity to <code>max(new_cap, inline_size())</code>.</p>
|
||
<p>Panics if <code>new_cap</code> is less than the vector’s length</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.reserve" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#934-936" title="goto source code">[src]</a></div><a href="#method.reserve" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.reserve" class="fnname">reserve</a>(&mut self, additional: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>)</h4></div></summary><div class="docblock"><p>Reserve capacity for <code>additional</code> more elements to be inserted.</p>
|
||
<p>May reserve more space to avoid frequent reallocations.</p>
|
||
<p>Panics if the capacity computation overflows <code>usize</code>.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.try_reserve" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#941-954" title="goto source code">[src]</a></div><a href="#method.try_reserve" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.try_reserve" class="fnname">try_reserve</a>(<br> &mut self, <br> additional: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a><br>) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.unit.html">()</a>, <a class="enum" href="enum.CollectionAllocErr.html" title="enum smallvec::CollectionAllocErr">CollectionAllocErr</a>></h4></div></summary><div class="docblock"><p>Reserve capacity for <code>additional</code> more elements to be inserted.</p>
|
||
<p>May reserve more space to avoid frequent reallocations.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.reserve_exact" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#959-961" title="goto source code">[src]</a></div><a href="#method.reserve_exact" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.reserve_exact" class="fnname">reserve_exact</a>(&mut self, additional: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>)</h4></div></summary><div class="docblock"><p>Reserve the minimum capacity for <code>additional</code> more elements to be inserted.</p>
|
||
<p>Panics if the new capacity overflows <code>usize</code>.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.try_reserve_exact" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#964-973" title="goto source code">[src]</a></div><a href="#method.try_reserve_exact" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.try_reserve_exact" class="fnname">try_reserve_exact</a>(<br> &mut self, <br> additional: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a><br>) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.unit.html">()</a>, <a class="enum" href="enum.CollectionAllocErr.html" title="enum smallvec::CollectionAllocErr">CollectionAllocErr</a>></h4></div></summary><div class="docblock"><p>Reserve the minimum capacity for <code>additional</code> more elements to be inserted.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.shrink_to_fit" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#979-995" title="goto source code">[src]</a></div><a href="#method.shrink_to_fit" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.shrink_to_fit" class="fnname">shrink_to_fit</a>(&mut self)</h4></div></summary><div class="docblock"><p>Shrink the capacity of the vector as much as possible.</p>
|
||
<p>When possible, this will move data from an external heap buffer to the vector’s inline
|
||
storage.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.truncate" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1004-1013" title="goto source code">[src]</a></div><a href="#method.truncate" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.truncate" class="fnname">truncate</a>(&mut self, len: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>)</h4></div></summary><div class="docblock"><p>Shorten the vector, keeping the first <code>len</code> elements and dropping the rest.</p>
|
||
<p>If <code>len</code> is greater than or equal to the vector’s current length, this has no
|
||
effect.</p>
|
||
<p>This does not re-allocate. If you want the vector’s capacity to shrink, call
|
||
<code>shrink_to_fit</code> after truncating.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.as_slice" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1018-1020" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.slice.html">&[</a>A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a></h4></div></summary><div class="docblock"><p>Extracts a slice containing the entire vector.</p>
|
||
<p>Equivalent to <code>&s[..]</code>.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.as_mut_slice" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1025-1027" title="goto source code">[src]</a></div><a href="#method.as_mut_slice" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.as_mut_slice" class="fnname">as_mut_slice</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [</a>A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a></h4></div></summary><div class="docblock"><p>Extracts a mutable slice of the entire vector.</p>
|
||
<p>Equivalent to <code>&mut s[..]</code>.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.swap_remove" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1035-1040" title="goto source code">[src]</a></div><a href="#method.swap_remove" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.swap_remove" class="fnname">swap_remove</a>(&mut self, index: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>) -> A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a></h4></div></summary><div class="docblock"><p>Remove the element at position <code>index</code>, replacing it with the last element.</p>
|
||
<p>This does not preserve ordering, but is O(1).</p>
|
||
<p>Panics if <code>index</code> is out of bounds.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.clear" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1044-1046" title="goto source code">[src]</a></div><a href="#method.clear" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.clear" class="fnname">clear</a>(&mut self)</h4></div></summary><div class="docblock"><p>Remove all elements from the vector.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.remove" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1052-1063" title="goto source code">[src]</a></div><a href="#method.remove" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.remove" class="fnname">remove</a>(&mut self, index: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>) -> A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a></h4></div></summary><div class="docblock"><p>Remove and return the element at position <code>index</code>, shifting all elements after it to the
|
||
left.</p>
|
||
<p>Panics if <code>index</code> is out of bounds.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.insert" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1068-1080" title="goto source code">[src]</a></div><a href="#method.insert" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.insert" class="fnname">insert</a>(&mut self, index: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>, element: A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>)</h4></div></summary><div class="docblock"><p>Insert an element at position <code>index</code>, shifting all elements after it to the right.</p>
|
||
<p>Panics if <code>index</code> is out of bounds.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.insert_many" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1084-1162" title="goto source code">[src]</a></div><a href="#method.insert_many" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.insert_many" class="fnname">insert_many</a><I: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a><Item = A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>>>(<br> &mut self, <br> index: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>, <br> iterable: I<br>)</h4></div></summary><div class="docblock"><p>Insert multiple elements at position <code>index</code>, shifting all following elements toward the
|
||
back.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.into_vec" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1166-1177" title="goto source code">[src]</a></div><a href="#method.into_vec" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.into_vec" class="fnname">into_vec</a>(self) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>></h4></div></summary><div class="docblock"><p>Convert a SmallVec to a Vec, without reallocating if the SmallVec has already spilled onto
|
||
the heap.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.into_boxed_slice" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1183-1185" title="goto source code">[src]</a></div><a href="#method.into_boxed_slice" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.into_boxed_slice" class="fnname">into_boxed_slice</a>(self) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">[</a>A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>></h4></div></summary><div class="docblock"><p>Converts a <code>SmallVec</code> into a <code>Box<[T]></code> without reallocating if the <code>SmallVec</code> has already spilled
|
||
onto the heap.</p>
|
||
<p>Note that this will drop any excess capacity.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.into_inner" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1191-1202" title="goto source code">[src]</a></div><a href="#method.into_inner" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.into_inner" class="fnname">into_inner</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><A, Self></h4></div></summary><div class="docblock"><p>Convert the SmallVec into an <code>A</code> if possible. Otherwise return <code>Err(Self)</code>.</p>
|
||
<p>This method returns <code>Err(Self)</code> if the SmallVec is too short (and the <code>A</code> contains uninitialized elements),
|
||
or if the SmallVec is too long (and all the elements were spilled to the heap).</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.retain" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1209-1220" title="goto source code">[src]</a></div><a href="#method.retain" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.retain" class="fnname">retain</a><F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&mut A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a>>(&mut self, f: F)</h4></div></summary><div class="docblock"><p>Retains only the elements specified by the predicate.</p>
|
||
<p>In other words, remove all elements <code>e</code> such that <code>f(&e)</code> returns <code>false</code>.
|
||
This method operates in place and preserves the order of the retained
|
||
elements.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.dedup" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1223-1228" title="goto source code">[src]</a></div><a href="#method.dedup" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.dedup" class="fnname">dedup</a>(&mut self) <span class="where fmt-newline">where<br> A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>>, </span></h4></div></summary><div class="docblock"><p>Removes consecutive duplicate elements.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.dedup_by" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1231-1260" title="goto source code">[src]</a></div><a href="#method.dedup_by" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.dedup_by" class="fnname">dedup_by</a><F>(&mut self, same_bucket: F) <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&mut A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>, &mut A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a>, </span></h4></div></summary><div class="docblock"><p>Removes consecutive duplicate elements using the given equality relation.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.dedup_by_key" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1263-1269" title="goto source code">[src]</a></div><a href="#method.dedup_by_key" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.dedup_by_key" class="fnname">dedup_by_key</a><F, K>(&mut self, key: F) <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&mut A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>) -> K,<br> K: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><K>, </span></h4></div></summary><div class="docblock"><p>Removes consecutive elements that map to the same key.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.resize_with" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1296-1311" title="goto source code">[src]</a></div><a href="#method.resize_with" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.resize_with" class="fnname">resize_with</a><F>(&mut self, new_len: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>, f: F) <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>() -> A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>, </span></h4></div></summary><div class="docblock"><p>Resizes the <code>SmallVec</code> in-place so that <code>len</code> is equal to <code>new_len</code>.</p>
|
||
<p>If <code>new_len</code> is greater than <code>len</code>, the <code>SmallVec</code> is extended by the difference, with each
|
||
additional slot filled with the result of calling the closure <code>f</code>. The return values from <code>f</code></p>
|
||
<p>If <code>new_len</code> is less than <code>len</code>, the <code>SmallVec</code> is simply truncated.</p>
|
||
<p>This method uses a closure to create new values on every push. If you’d rather <code>Clone</code> a given
|
||
value, use <code>resize</code>. If you want to use the <code>Default</code> trait to generate values, you can pass
|
||
<code>Default::default()</code> as the second argument.</p>
|
||
<p>Added for std::vec::Vec compatibility (added in Rust 1.33.0)</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">vec</span> : <span class="ident">SmallVec</span><span class="op"><</span>[<span class="kw">_</span>; <span class="number">4</span>]<span class="op">></span> <span class="op">=</span> <span class="macro">smallvec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
<span class="ident">vec</span>.<span class="ident">resize_with</span>(<span class="number">5</span>, <span class="ident">Default::default</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span><span class="kw-2">*</span><span class="ident">vec</span>, <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">0</span>, <span class="number">0</span>]);
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> : <span class="ident">SmallVec</span><span class="op"><</span>[<span class="kw">_</span>; <span class="number">4</span>]<span class="op">></span> <span class="op">=</span> <span class="macro">smallvec!</span>[];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">p</span> <span class="op">=</span> <span class="number">1</span>;
|
||
<span class="ident">vec</span>.<span class="ident">resize_with</span>(<span class="number">4</span>, <span class="op">|</span><span class="op">|</span> { <span class="ident">p</span> <span class="kw-2">*</span><span class="op">=</span> <span class="number">2</span>; <span class="ident">p</span> });
|
||
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span><span class="kw-2">*</span><span class="ident">vec</span>, <span class="kw-2">&</span>[<span class="number">2</span>, <span class="number">4</span>, <span class="number">8</span>, <span class="number">16</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.from_raw_parts" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1382-1388" title="goto source code">[src]</a></div><a href="#method.from_raw_parts" class="anchor"></a><h4 class="code-header">pub unsafe fn <a href="#method.from_raw_parts" class="fnname">from_raw_parts</a>(<br> ptr: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.pointer.html">*mut </a>A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>, <br> length: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>, <br> capacity: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a><br>) -> <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h4></div></summary><div class="docblock"><p>Creates a <code>SmallVec</code> directly from the raw components of another
|
||
<code>SmallVec</code>.</p>
|
||
<h5 id="safety" class="section-header"><a href="#safety">Safety</a></h5>
|
||
<p>This is highly unsafe, due to the number of invariants that aren’t
|
||
checked:</p>
|
||
<ul>
|
||
<li><code>ptr</code> needs to have been previously allocated via <code>SmallVec</code> for its
|
||
spilled storage (at least, it’s highly likely to be incorrect if it
|
||
wasn’t).</li>
|
||
<li><code>ptr</code>’s <code>A::Item</code> type needs to be the same size and alignment that
|
||
it was allocated with</li>
|
||
<li><code>length</code> needs to be less than or equal to <code>capacity</code>.</li>
|
||
<li><code>capacity</code> needs to be the capacity that the pointer was allocated
|
||
with.</li>
|
||
</ul>
|
||
<p>Violating these may cause problems like corrupting the allocator’s
|
||
internal data structures.</p>
|
||
<p>Additionally, <code>capacity</code> must be greater than the amount of inline
|
||
storage <code>A</code> has; that is, the new <code>SmallVec</code> must need to spill over
|
||
into heap allocated storage. This condition is asserted against.</p>
|
||
<p>The ownership of <code>ptr</code> is effectively transferred to the
|
||
<code>SmallVec</code> which may then deallocate, reallocate or change the
|
||
contents of memory pointed to by the pointer at will. Ensure
|
||
that nothing else uses the pointer after calling this
|
||
function.</p>
|
||
<h5 id="examples" class="section-header"><a href="#examples">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::mem</span>;
|
||
<span class="kw">use</span> <span class="ident">std::ptr</span>;
|
||
|
||
<span class="kw">fn</span> <span class="ident">main</span>() {
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">v</span>: <span class="ident">SmallVec</span><span class="op"><</span>[<span class="kw">_</span>; <span class="number">1</span>]<span class="op">></span> <span class="op">=</span> <span class="macro">smallvec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
|
||
<span class="comment">// Pull out the important parts of `v`.</span>
|
||
<span class="kw">let</span> <span class="ident">p</span> <span class="op">=</span> <span class="ident">v</span>.<span class="ident">as_mut_ptr</span>();
|
||
<span class="kw">let</span> <span class="ident">len</span> <span class="op">=</span> <span class="ident">v</span>.<span class="ident">len</span>();
|
||
<span class="kw">let</span> <span class="ident">cap</span> <span class="op">=</span> <span class="ident">v</span>.<span class="ident">capacity</span>();
|
||
<span class="kw">let</span> <span class="ident">spilled</span> <span class="op">=</span> <span class="ident">v</span>.<span class="ident">spilled</span>();
|
||
|
||
<span class="kw">unsafe</span> {
|
||
<span class="comment">// Forget all about `v`. The heap allocation that stored the</span>
|
||
<span class="comment">// three values won't be deallocated.</span>
|
||
<span class="ident">mem::forget</span>(<span class="ident">v</span>);
|
||
|
||
<span class="comment">// Overwrite memory with [4, 5, 6].</span>
|
||
<span class="comment">//</span>
|
||
<span class="comment">// This is only safe if `spilled` is true! Otherwise, we are</span>
|
||
<span class="comment">// writing into the old `SmallVec`'s inline storage on the</span>
|
||
<span class="comment">// stack.</span>
|
||
<span class="macro">assert!</span>(<span class="ident">spilled</span>);
|
||
<span class="kw">for</span> <span class="ident">i</span> <span class="kw">in</span> <span class="number">0</span>..<span class="ident">len</span> {
|
||
<span class="ident">ptr::write</span>(<span class="ident">p</span>.<span class="ident">add</span>(<span class="ident">i</span>), <span class="number">4</span> <span class="op">+</span> <span class="ident">i</span>);
|
||
}
|
||
|
||
<span class="comment">// Put everything back together into a SmallVec with a different</span>
|
||
<span class="comment">// amount of inline storage, but which is still less than `cap`.</span>
|
||
<span class="kw">let</span> <span class="ident">rebuilt</span> <span class="op">=</span> <span class="ident">SmallVec</span>::<span class="op"><</span>[<span class="kw">_</span>; <span class="number">2</span>]<span class="op">></span><span class="ident">::from_raw_parts</span>(<span class="ident">p</span>, <span class="ident">len</span>, <span class="ident">cap</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span><span class="kw-2">*</span><span class="ident">rebuilt</span>, <span class="kw-2">&</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><div id="method.as_ptr" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1391-1396" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.pointer.html">*const </a>A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a></h4></div></summary><div class="docblock"><p>Returns a raw pointer to the vector’s buffer.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.as_mut_ptr" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1399-1404" title="goto source code">[src]</a></div><a href="#method.as_mut_ptr" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.as_mut_ptr" class="fnname">as_mut_ptr</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.pointer.html">*mut </a>A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a></h4></div></summary><div class="docblock"><p>Returns a raw mutable pointer to the vector’s buffer.</p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-1" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1407-1467" title="goto source code">[src]</a></div><a href="#impl-1" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A> <span class="where fmt-newline">where<br> A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/marker/trait.Copy.html" title="trait core::marker::Copy">Copy</a>, </span></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.from_slice" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1414-1438" title="goto source code">[src]</a></div><a href="#method.from_slice" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.from_slice" class="fnname">from_slice</a>(slice: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[</a>A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>) -> Self</h4></div></summary><div class="docblock"><p>Copy the elements from a slice into a new <code>SmallVec</code>.</p>
|
||
<p>For slices of <code>Copy</code> types, this is more efficient than <code>SmallVec::from(slice)</code>.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.insert_from_slice" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1444-1457" title="goto source code">[src]</a></div><a href="#method.insert_from_slice" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.insert_from_slice" class="fnname">insert_from_slice</a>(&mut self, index: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>, slice: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[</a>A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>)</h4></div></summary><div class="docblock"><p>Copy elements from a slice into the vector at position <code>index</code>, shifting any following
|
||
elements toward the back.</p>
|
||
<p>For slices of <code>Copy</code> types, this is more efficient than <code>insert</code>.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.extend_from_slice" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1463-1466" title="goto source code">[src]</a></div><a href="#method.extend_from_slice" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.extend_from_slice" class="fnname">extend_from_slice</a>(&mut self, slice: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[</a>A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>)</h4></div></summary><div class="docblock"><p>Copy elements from a slice and append them to the vector.</p>
|
||
<p>For slices of <code>Copy</code> types, this is more efficient than <code>extend</code>.</p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-2" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1469-1513" title="goto source code">[src]</a></div><a href="#impl-2" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A> <span class="where fmt-newline">where<br> A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, </span></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.resize" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1479-1487" title="goto source code">[src]</a></div><a href="#method.resize" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.resize" class="fnname">resize</a>(&mut self, len: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>, value: A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>)</h4></div></summary><div class="docblock"><p>Resizes the vector so that its length is equal to <code>len</code>.</p>
|
||
<p>If <code>len</code> is less than the current length, the vector simply truncated.</p>
|
||
<p>If <code>len</code> is greater than the current length, <code>value</code> is appended to the
|
||
vector until its length equals <code>len</code>.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.from_elem" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1496-1512" title="goto source code">[src]</a></div><a href="#method.from_elem" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.from_elem" class="fnname">from_elem</a>(elem: A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>, n: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>) -> Self</h4></div></summary><div class="docblock"><p>Creates a <code>SmallVec</code> with <code>n</code> copies of <code>elem</code>.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">smallvec::SmallVec</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="ident">SmallVec</span>::<span class="op"><</span>[<span class="ident">char</span>; <span class="number">128</span>]<span class="op">></span><span class="ident">::from_elem</span>(<span class="string">'d'</span>, <span class="number">2</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, <span class="ident">SmallVec::from_buf</span>([<span class="string">'d'</span>, <span class="string">'d'</span>]));</code></pre></div>
|
||
</div></details></div></details><h2 id="deref-methods-%5BA%3A%3AItem%5D" class="small-section-header"><span>Methods from <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a><Target = <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">[</a>A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>></span><a href="#deref-methods-%5BA%3A%3AItem%5D" class="anchor"></a></h2><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.len-1" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#126" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a></h4></div></summary><div class="docblock"><p>Returns the number of elements in the slice.</p>
|
||
<h5 id="examples-1" class="section-header"><a href="#examples-1">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><div id="method.is_empty-1" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#148" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.bool.html">bool</a></h4></div></summary><div class="docblock"><p>Returns <code>true</code> if the slice has a length of 0.</p>
|
||
<h5 id="examples-2" class="section-header"><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">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><div id="method.first" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#166" title="goto source code">[src]</a></div><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/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T></h4></div></summary><div class="docblock"><p>Returns the first element of the slice, or <code>None</code> if it is empty.</p>
|
||
<h5 id="examples-3" class="section-header"><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">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><div id="method.first_mut" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#185" title="goto source code">[src]</a></div><a href="#method.first_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.first_mut" class="fnname">first_mut</a>(&mut self) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&mut </a>T></h4></div></summary><div class="docblock"><p>Returns a mutable pointer to the first element of the slice, or <code>None</code> if it is empty.</p>
|
||
<h5 id="examples-4" class="section-header"><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="ident">x</span> <span class="op">=</span> <span class="kw-2">&mut</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="op">=</span> <span class="ident">x</span>.<span class="ident">first_mut</span>() {
|
||
<span class="kw-2">*</span><span class="ident">first</span> <span class="op">=</span> <span class="number">5</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">x</span>, <span class="kw-2">&</span>[<span class="number">5</span>, <span class="number">1</span>, <span class="number">2</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.split_first" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#204" title="goto source code">[src]</a></div><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/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a>></h4></div></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-5" class="section-header"><a href="#examples-5">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><div id="method.split_first_mut" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#225" title="goto source code">[src]</a></div><a href="#method.split_first_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.split_first_mut" class="fnname">split_first_mut</a>(&mut self) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&mut </a>T, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a>></h4></div></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-6" class="section-header"><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">x</span> <span class="op">=</span> <span class="kw-2">&mut</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_mut</span>() {
|
||
<span class="kw-2">*</span><span class="ident">first</span> <span class="op">=</span> <span class="number">3</span>;
|
||
<span class="ident">elements</span>[<span class="number">0</span>] <span class="op">=</span> <span class="number">4</span>;
|
||
<span class="ident">elements</span>[<span class="number">1</span>] <span class="op">=</span> <span class="number">5</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">x</span>, <span class="kw-2">&</span>[<span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.split_last" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#244" title="goto source code">[src]</a></div><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/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a>></h4></div></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-7" class="section-header"><a href="#examples-7">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><div id="method.split_last_mut" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#265" title="goto source code">[src]</a></div><a href="#method.split_last_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.split_last_mut" class="fnname">split_last_mut</a>(&mut self) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&mut </a>T, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a>></h4></div></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-8" class="section-header"><a href="#examples-8">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">&mut</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_mut</span>() {
|
||
<span class="kw-2">*</span><span class="ident">last</span> <span class="op">=</span> <span class="number">3</span>;
|
||
<span class="ident">elements</span>[<span class="number">0</span>] <span class="op">=</span> <span class="number">4</span>;
|
||
<span class="ident">elements</span>[<span class="number">1</span>] <span class="op">=</span> <span class="number">5</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">x</span>, <span class="kw-2">&</span>[<span class="number">4</span>, <span class="number">5</span>, <span class="number">3</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.last" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#283" title="goto source code">[src]</a></div><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/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T></h4></div></summary><div class="docblock"><p>Returns the last element of the slice, or <code>None</code> if it is empty.</p>
|
||
<h5 id="examples-9" class="section-header"><a href="#examples-9">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><div id="method.last_mut" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#302" title="goto source code">[src]</a></div><a href="#method.last_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.last_mut" class="fnname">last_mut</a>(&mut self) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&mut </a>T></h4></div></summary><div class="docblock"><p>Returns a mutable pointer to the last item in the slice.</p>
|
||
<h5 id="examples-10" class="section-header"><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">x</span> <span class="op">=</span> <span class="kw-2">&mut</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="op">=</span> <span class="ident">x</span>.<span class="ident">last_mut</span>() {
|
||
<span class="kw-2">*</span><span class="ident">last</span> <span class="op">=</span> <span class="number">10</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">x</span>, <span class="kw-2">&</span>[<span class="number">0</span>, <span class="number">1</span>, <span class="number">10</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.get" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#325-327" title="goto source code">[src]</a></div><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/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&<I as <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/slice/index/trait.SliceIndex.html" title="trait core::slice::index::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.59.0/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/1.59.0/core/slice/index/trait.SliceIndex.html" title="trait core::slice::index::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>>, </span></h4></div></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-11" class="section-header"><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">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><div id="method.get_mut" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#349-351" title="goto source code">[src]</a></div><a href="#method.get_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.get_mut" class="fnname">get_mut</a><I>(<br> &mut self, <br> index: I<br>) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&mut <I as <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/slice/index/trait.SliceIndex.html" title="trait core::slice::index::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.59.0/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/1.59.0/core/slice/index/trait.SliceIndex.html" title="trait core::slice::index::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>>, </span></h4></div></summary><div class="docblock"><p>Returns a mutable reference to an element or subslice depending on the
|
||
type of index (see <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.get"><code>get</code></a>) or <code>None</code> if the index is out of bounds.</p>
|
||
<h5 id="examples-12" class="section-header"><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">x</span> <span class="op">=</span> <span class="kw-2">&mut</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">elem</span>) <span class="op">=</span> <span class="ident">x</span>.<span class="ident">get_mut</span>(<span class="number">1</span>) {
|
||
<span class="kw-2">*</span><span class="ident">elem</span> <span class="op">=</span> <span class="number">42</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">x</span>, <span class="kw-2">&</span>[<span class="number">0</span>, <span class="number">42</span>, <span class="number">2</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.get_unchecked" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#380-382" title="goto source code">[src]</a></div><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/1.59.0/core/slice/index/trait.SliceIndex.html" title="trait core::slice::index::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.59.0/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/1.59.0/core/slice/index/trait.SliceIndex.html" title="trait core::slice::index::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>>, </span></h4></div></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/1.59.0/core/primitive.slice.html#method.get"><code>get</code></a>.</p>
|
||
<h5 id="safety-1" class="section-header"><a href="#safety-1">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-13" class="section-header"><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">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><div id="method.get_unchecked_mut" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#416-418" title="goto source code">[src]</a></div><a href="#method.get_unchecked_mut" class="anchor"></a><h4 class="code-header">pub unsafe fn <a href="#method.get_unchecked_mut" class="fnname">get_unchecked_mut</a><I>(<br> &mut self, <br> index: I<br>) -> &mut <I as <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/slice/index/trait.SliceIndex.html" title="trait core::slice::index::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.59.0/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/1.59.0/core/slice/index/trait.SliceIndex.html" title="trait core::slice::index::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>>, </span></h4></div></summary><div class="docblock"><p>Returns a mutable reference to an element or subslice, without doing
|
||
bounds checking.</p>
|
||
<p>For a safe alternative see <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.get_mut"><code>get_mut</code></a>.</p>
|
||
<h5 id="safety-2" class="section-header"><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.</p>
|
||
<h5 id="examples-14" class="section-header"><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">&mut</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">4</span>];
|
||
|
||
<span class="kw">unsafe</span> {
|
||
<span class="kw">let</span> <span class="ident">elem</span> <span class="op">=</span> <span class="ident">x</span>.<span class="ident">get_unchecked_mut</span>(<span class="number">1</span>);
|
||
<span class="kw-2">*</span><span class="ident">elem</span> <span class="op">=</span> <span class="number">13</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">x</span>, <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">13</span>, <span class="number">4</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.as_ptr-1" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#455" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.pointer.html">*const T</a></h4></div></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/1.59.0/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-15" class="section-header"><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">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><div id="method.as_mut_ptr-1" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#483" title="goto source code">[src]</a></div><a href="#method.as_mut_ptr-1" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.as_mut_ptr-1" class="fnname">as_mut_ptr</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.pointer.html">*mut T</a></h4></div></summary><div class="docblock"><p>Returns an unsafe mutable 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>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-16" class="section-header"><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">x</span> <span class="op">=</span> <span class="kw-2">&mut</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_mut_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="kw-2">*</span><span class="ident">x_ptr</span>.<span class="ident">add</span>(<span class="ident">i</span>) <span class="op">+</span><span class="op">=</span> <span class="number">2</span>;
|
||
}
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">x</span>, <span class="kw-2">&</span>[<span class="number">3</span>, <span class="number">4</span>, <span class="number">6</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.as_ptr_range" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#518" title="goto source code">[src]</a></div><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/1.59.0/core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.pointer.html">*const T</a>></h4></div></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/1.59.0/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><div id="method.as_mut_ptr_range" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#560" title="goto source code">[src]</a></div><a href="#method.as_mut_ptr_range" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.as_mut_ptr_range" class="fnname">as_mut_ptr_range</a>(&mut self) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.pointer.html">*mut T</a>></h4></div></summary><div class="docblock"><p>Returns the two unsafe mutable 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/1.59.0/core/primitive.slice.html#method.as_mut_ptr"><code>as_mut_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>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.swap" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#589" title="goto source code">[src]</a></div><a href="#method.swap" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.swap" class="fnname">swap</a>(&mut self, a: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>, b: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>)</h4></div></summary><div class="docblock"><p>Swaps two elements in the slice.</p>
|
||
<h5 id="arguments" class="section-header"><a href="#arguments">Arguments</a></h5>
|
||
<ul>
|
||
<li>a - The index of the first element</li>
|
||
<li>b - The index of the second element</li>
|
||
</ul>
|
||
<h5 id="panics-1" class="section-header"><a href="#panics-1">Panics</a></h5>
|
||
<p>Panics if <code>a</code> or <code>b</code> are out of bounds.</p>
|
||
<h5 id="examples-17" class="section-header"><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="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> [<span class="string">"a"</span>, <span class="string">"b"</span>, <span class="string">"c"</span>, <span class="string">"d"</span>, <span class="string">"e"</span>];
|
||
<span class="ident">v</span>.<span class="ident">swap</span>(<span class="number">2</span>, <span class="number">4</span>);
|
||
<span class="macro">assert!</span>(<span class="ident">v</span> <span class="op">==</span> [<span class="string">"a"</span>, <span class="string">"b"</span>, <span class="string">"e"</span>, <span class="string">"d"</span>, <span class="string">"c"</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.swap_unchecked" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#626" title="goto source code">[src]</a></div><a href="#method.swap_unchecked" class="anchor"></a><h4 class="code-header">pub unsafe fn <a href="#method.swap_unchecked" class="fnname">swap_unchecked</a>(&mut self, a: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>, b: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>)</h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_swap_unchecked</code>)</div></div></summary><div class="docblock"><p>Swaps two elements in the slice, without doing bounds checking.</p>
|
||
<p>For a safe alternative see <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.swap"><code>swap</code></a>.</p>
|
||
<h5 id="arguments-1" class="section-header"><a href="#arguments-1">Arguments</a></h5>
|
||
<ul>
|
||
<li>a - The index of the first element</li>
|
||
<li>b - The index of the second element</li>
|
||
</ul>
|
||
<h5 id="safety-3" class="section-header"><a href="#safety-3">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>.
|
||
The caller has to ensure that <code>a < self.len()</code> and <code>b < self.len()</code>.</p>
|
||
<h5 id="examples-18" class="section-header"><a href="#examples-18">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_swap_unchecked</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> [<span class="string">"a"</span>, <span class="string">"b"</span>, <span class="string">"c"</span>, <span class="string">"d"</span>];
|
||
<span class="comment">// SAFETY: we know that 1 and 3 are both indices of the slice</span>
|
||
<span class="kw">unsafe</span> { <span class="ident">v</span>.<span class="ident">swap_unchecked</span>(<span class="number">1</span>, <span class="number">3</span>) };
|
||
<span class="macro">assert!</span>(<span class="ident">v</span> <span class="op">==</span> [<span class="string">"a"</span>, <span class="string">"d"</span>, <span class="string">"c"</span>, <span class="string">"b"</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.reverse" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#651" title="goto source code">[src]</a></div><a href="#method.reverse" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.reverse" class="fnname">reverse</a>(&mut self)</h4></div></summary><div class="docblock"><p>Reverses the order of elements in the slice, in place.</p>
|
||
<h5 id="examples-19" class="section-header"><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="kw-2">mut</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="ident">v</span>.<span class="ident">reverse</span>();
|
||
<span class="macro">assert!</span>(<span class="ident">v</span> <span class="op">==</span> [<span class="number">3</span>, <span class="number">2</span>, <span class="number">1</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.iter" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#705" title="goto source code">[src]</a></div><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/1.59.0/core/slice/iter/struct.Iter.html" title="struct core::slice::iter::Iter">Iter</a><'_, T></h4></div></summary><div class="docblock"><p>Returns an iterator over the slice.</p>
|
||
<h5 id="examples-20" class="section-header"><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">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><div id="method.iter_mut" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#722" title="goto source code">[src]</a></div><a href="#method.iter_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.iter_mut" class="fnname">iter_mut</a>(&mut self) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.IterMut.html" title="struct core::slice::iter::IterMut">IterMut</a><'_, T></h4></div></summary><div class="docblock"><p>Returns an iterator that allows modifying each value.</p>
|
||
<h5 id="examples-21" class="section-header"><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">x</span> <span class="op">=</span> <span class="kw-2">&mut</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">4</span>];
|
||
<span class="kw">for</span> <span class="ident">elem</span> <span class="kw">in</span> <span class="ident">x</span>.<span class="ident">iter_mut</span>() {
|
||
<span class="kw-2">*</span><span class="ident">elem</span> <span class="op">+</span><span class="op">=</span> <span class="number">2</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">x</span>, <span class="kw-2">&</span>[<span class="number">3</span>, <span class="number">4</span>, <span class="number">6</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.windows" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#754" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.Windows.html" title="struct core::slice::iter::Windows">Windows</a><'_, T></h4></div></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-2" class="section-header"><a href="#panics-2">Panics</a></h5>
|
||
<p>Panics if <code>size</code> is 0.</p>
|
||
<h5 id="examples-22" class="section-header"><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">'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><div id="method.chunks" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#788" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.Chunks.html" title="struct core::slice::iter::Chunks">Chunks</a><'_, T></h4></div></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/1.59.0/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/1.59.0/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-3" class="section-header"><a href="#panics-3">Panics</a></h5>
|
||
<p>Panics if <code>chunk_size</code> is 0.</p>
|
||
<h5 id="examples-23" class="section-header"><a href="#examples-23">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><div id="method.chunks_mut" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#826" title="goto source code">[src]</a></div><a href="#method.chunks_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.chunks_mut" class="fnname">chunks_mut</a>(&mut self, chunk_size: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.ChunksMut.html" title="struct core::slice::iter::ChunksMut">ChunksMut</a><'_, T></h4></div></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 mutable 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/1.59.0/core/primitive.slice.html#method.chunks_exact_mut"><code>chunks_exact_mut</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/1.59.0/core/primitive.slice.html#method.rchunks_mut"><code>rchunks_mut</code></a> for the same iterator but starting at
|
||
the end of the slice.</p>
|
||
<h5 id="panics-4" class="section-header"><a href="#panics-4">Panics</a></h5>
|
||
<p>Panics if <code>chunk_size</code> is 0.</p>
|
||
<h5 id="examples-24" class="section-header"><a href="#examples-24">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">&mut</span> [<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">count</span> <span class="op">=</span> <span class="number">1</span>;
|
||
|
||
<span class="kw">for</span> <span class="ident">chunk</span> <span class="kw">in</span> <span class="ident">v</span>.<span class="ident">chunks_mut</span>(<span class="number">2</span>) {
|
||
<span class="kw">for</span> <span class="ident">elem</span> <span class="kw">in</span> <span class="ident">chunk</span>.<span class="ident">iter_mut</span>() {
|
||
<span class="kw-2">*</span><span class="ident">elem</span> <span class="op">+</span><span class="op">=</span> <span class="ident">count</span>;
|
||
}
|
||
<span class="ident">count</span> <span class="op">+</span><span class="op">=</span> <span class="number">1</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, <span class="kw-2">&</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>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.chunks_exact" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#863" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.ChunksExact.html" title="struct core::slice::iter::ChunksExact">ChunksExact</a><'_, T></h4></div></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/1.59.0/core/primitive.slice.html#method.chunks"><code>chunks</code></a>.</p>
|
||
<p>See <a href="https://doc.rust-lang.org/1.59.0/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/1.59.0/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-5" class="section-header"><a href="#panics-5">Panics</a></h5>
|
||
<p>Panics if <code>chunk_size</code> is 0.</p>
|
||
<h5 id="examples-25" class="section-header"><a href="#examples-25">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><div id="method.chunks_exact_mut" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#905" title="goto source code">[src]</a></div><a href="#method.chunks_exact_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.chunks_exact_mut" class="fnname">chunks_exact_mut</a>(&mut self, chunk_size: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.ChunksExactMut.html" title="struct core::slice::iter::ChunksExactMut">ChunksExactMut</a><'_, T></h4></div></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 mutable 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>into_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/1.59.0/core/primitive.slice.html#method.chunks_mut"><code>chunks_mut</code></a>.</p>
|
||
<p>See <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.chunks_mut"><code>chunks_mut</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/1.59.0/core/primitive.slice.html#method.rchunks_exact_mut"><code>rchunks_exact_mut</code></a> for the same iterator but starting at the end of
|
||
the slice.</p>
|
||
<h5 id="panics-6" class="section-header"><a href="#panics-6">Panics</a></h5>
|
||
<p>Panics if <code>chunk_size</code> is 0.</p>
|
||
<h5 id="examples-26" class="section-header"><a href="#examples-26">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">&mut</span> [<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">count</span> <span class="op">=</span> <span class="number">1</span>;
|
||
|
||
<span class="kw">for</span> <span class="ident">chunk</span> <span class="kw">in</span> <span class="ident">v</span>.<span class="ident">chunks_exact_mut</span>(<span class="number">2</span>) {
|
||
<span class="kw">for</span> <span class="ident">elem</span> <span class="kw">in</span> <span class="ident">chunk</span>.<span class="ident">iter_mut</span>() {
|
||
<span class="kw-2">*</span><span class="ident">elem</span> <span class="op">+</span><span class="op">=</span> <span class="ident">count</span>;
|
||
}
|
||
<span class="ident">count</span> <span class="op">+</span><span class="op">=</span> <span class="number">1</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">2</span>, <span class="number">0</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.as_chunks_unchecked" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#939" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a>>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">; N]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_as_chunks</code>)</div></div></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-4" class="section-header"><a href="#safety-4">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-27" class="section-header"><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">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><div id="method.as_chunks" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#970" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a>>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">; N]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_as_chunks</code>)</div></div></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-7" class="section-header"><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-28" class="section-header"><a href="#examples-28">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><div id="method.as_rchunks" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#1000" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a>>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[T]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">; N]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_as_chunks</code>)</div></div></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-8" class="section-header"><a href="#panics-8">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-29" class="section-header"><a href="#examples-29">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><div id="method.array_chunks" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#1039" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a>>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.ArrayChunks.html" title="struct core::slice::iter::ArrayChunks">ArrayChunks</a><'_, T, N></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>array_chunks</code>)</div></div></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/1.59.0/core/primitive.slice.html#method.chunks_exact"><code>chunks_exact</code></a>.</p>
|
||
<h5 id="panics-9" class="section-header"><a href="#panics-9">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-30" class="section-header"><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">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><div id="method.as_chunks_unchecked_mut" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#1075" title="goto source code">[src]</a></div><a href="#method.as_chunks_unchecked_mut" class="anchor"></a><h4 class="code-header">pub unsafe fn <a href="#method.as_chunks_unchecked_mut" class="fnname">as_chunks_unchecked_mut</a><const N: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>>(<br> &mut self<br>) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">; N]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_as_chunks</code>)</div></div></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-5" class="section-header"><a href="#safety-5">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-31" class="section-header"><a href="#examples-31">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">&mut</span> [<span class="ident">char</span>] <span class="op">=</span> <span class="kw-2">&mut</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">&mut</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_mut</span>() };
|
||
<span class="ident">chunks</span>[<span class="number">0</span>] <span class="op">=</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">'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">&mut</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_mut</span>() };
|
||
<span class="ident">chunks</span>[<span class="number">1</span>] <span class="op">=</span> [<span class="string">'a'</span>, <span class="string">'x'</span>, <span class="string">'?'</span>];
|
||
<span class="macro">assert_eq!</span>(<span class="ident">slice</span>, <span class="kw-2">&</span>[<span class="string">'L'</span>, <span class="string">'o'</span>, <span class="string">'r'</span>, <span class="string">'a'</span>, <span class="string">'x'</span>, <span class="string">'?'</span>]);
|
||
|
||
<span class="comment">// These would be unsound:</span>
|
||
<span class="comment">// let chunks: &[[_; 5]] = slice.as_chunks_unchecked_mut() // The slice length is not a multiple of 5</span>
|
||
<span class="comment">// let chunks: &[[_; 0]] = slice.as_chunks_unchecked_mut() // Zero-length chunks are never allowed</span></code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.as_chunks_mut" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#1112" title="goto source code">[src]</a></div><a href="#method.as_chunks_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.as_chunks_mut" class="fnname">as_chunks_mut</a><const N: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">; N]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_as_chunks</code>)</div></div></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-10" class="section-header"><a href="#panics-10">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-32" class="section-header"><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_as_chunks</span>)]</span>
|
||
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&mut</span> [<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">count</span> <span class="op">=</span> <span class="number">1</span>;
|
||
|
||
<span class="kw">let</span> (<span class="ident">chunks</span>, <span class="ident">remainder</span>) <span class="op">=</span> <span class="ident">v</span>.<span class="ident">as_chunks_mut</span>();
|
||
<span class="ident">remainder</span>[<span class="number">0</span>] <span class="op">=</span> <span class="number">9</span>;
|
||
<span class="kw">for</span> <span class="ident">chunk</span> <span class="kw">in</span> <span class="ident">chunks</span> {
|
||
<span class="kw-2">*</span><span class="ident">chunk</span> <span class="op">=</span> [<span class="ident">count</span>; <span class="number">2</span>];
|
||
<span class="ident">count</span> <span class="op">+</span><span class="op">=</span> <span class="number">1</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">2</span>, <span class="number">9</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.as_rchunks_mut" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#1148" title="goto source code">[src]</a></div><a href="#method.as_rchunks_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.as_rchunks_mut" class="fnname">as_rchunks_mut</a><const N: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">; N]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_as_chunks</code>)</div></div></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-11" class="section-header"><a href="#panics-11">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-33" class="section-header"><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">slice_as_chunks</span>)]</span>
|
||
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&mut</span> [<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">count</span> <span class="op">=</span> <span class="number">1</span>;
|
||
|
||
<span class="kw">let</span> (<span class="ident">remainder</span>, <span class="ident">chunks</span>) <span class="op">=</span> <span class="ident">v</span>.<span class="ident">as_rchunks_mut</span>();
|
||
<span class="ident">remainder</span>[<span class="number">0</span>] <span class="op">=</span> <span class="number">9</span>;
|
||
<span class="kw">for</span> <span class="ident">chunk</span> <span class="kw">in</span> <span class="ident">chunks</span> {
|
||
<span class="kw-2">*</span><span class="ident">chunk</span> <span class="op">=</span> [<span class="ident">count</span>; <span class="number">2</span>];
|
||
<span class="ident">count</span> <span class="op">+</span><span class="op">=</span> <span class="number">1</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, <span class="kw-2">&</span>[<span class="number">9</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">2</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.array_chunks_mut" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#1189" title="goto source code">[src]</a></div><a href="#method.array_chunks_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.array_chunks_mut" class="fnname">array_chunks_mut</a><const N: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>>(&mut self) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.ArrayChunksMut.html" title="struct core::slice::iter::ArrayChunksMut">ArrayChunksMut</a><'_, T, N></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>array_chunks</code>)</div></div></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 mutable 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>into_remainder</code> function of the iterator.</p>
|
||
<p>This method is the const generic equivalent of <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.chunks_exact_mut"><code>chunks_exact_mut</code></a>.</p>
|
||
<h5 id="panics-12" class="section-header"><a href="#panics-12">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-34" class="section-header"><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">array_chunks</span>)]</span>
|
||
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&mut</span> [<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">count</span> <span class="op">=</span> <span class="number">1</span>;
|
||
|
||
<span class="kw">for</span> <span class="ident">chunk</span> <span class="kw">in</span> <span class="ident">v</span>.<span class="ident">array_chunks_mut</span>() {
|
||
<span class="kw-2">*</span><span class="ident">chunk</span> <span class="op">=</span> [<span class="ident">count</span>; <span class="number">2</span>];
|
||
<span class="ident">count</span> <span class="op">+</span><span class="op">=</span> <span class="number">1</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">2</span>, <span class="number">0</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.array_windows" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#1221" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a>>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.ArrayWindows.html" title="struct core::slice::iter::ArrayWindows">ArrayWindows</a><'_, T, N></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>array_windows</code>)</div></div></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/1.59.0/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-13" class="section-header"><a href="#panics-13">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-35" class="section-header"><a href="#examples-35">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><div id="method.rchunks" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#1255" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.RChunks.html" title="struct core::slice::iter::RChunks">RChunks</a><'_, T></h4></div></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/1.59.0/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/1.59.0/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-14" class="section-header"><a href="#panics-14">Panics</a></h5>
|
||
<p>Panics if <code>chunk_size</code> is 0.</p>
|
||
<h5 id="examples-36" class="section-header"><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="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><div id="method.rchunks_mut" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#1293" title="goto source code">[src]</a></div><a href="#method.rchunks_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.rchunks_mut" class="fnname">rchunks_mut</a>(&mut self, chunk_size: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.RChunksMut.html" title="struct core::slice::iter::RChunksMut">RChunksMut</a><'_, T></h4></div></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 mutable 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/1.59.0/core/primitive.slice.html#method.rchunks_exact_mut"><code>rchunks_exact_mut</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/1.59.0/core/primitive.slice.html#method.chunks_mut"><code>chunks_mut</code></a> for the same iterator but starting at the
|
||
beginning of the slice.</p>
|
||
<h5 id="panics-15" class="section-header"><a href="#panics-15">Panics</a></h5>
|
||
<p>Panics if <code>chunk_size</code> is 0.</p>
|
||
<h5 id="examples-37" class="section-header"><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">v</span> <span class="op">=</span> <span class="kw-2">&mut</span> [<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">count</span> <span class="op">=</span> <span class="number">1</span>;
|
||
|
||
<span class="kw">for</span> <span class="ident">chunk</span> <span class="kw">in</span> <span class="ident">v</span>.<span class="ident">rchunks_mut</span>(<span class="number">2</span>) {
|
||
<span class="kw">for</span> <span class="ident">elem</span> <span class="kw">in</span> <span class="ident">chunk</span>.<span class="ident">iter_mut</span>() {
|
||
<span class="kw-2">*</span><span class="ident">elem</span> <span class="op">+</span><span class="op">=</span> <span class="ident">count</span>;
|
||
}
|
||
<span class="ident">count</span> <span class="op">+</span><span class="op">=</span> <span class="number">1</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, <span class="kw-2">&</span>[<span class="number">3</span>, <span class="number">2</span>, <span class="number">2</span>, <span class="number">1</span>, <span class="number">1</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.rchunks_exact" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#1332" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.RChunksExact.html" title="struct core::slice::iter::RChunksExact">RChunksExact</a><'_, T></h4></div></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/1.59.0/core/primitive.slice.html#method.chunks"><code>chunks</code></a>.</p>
|
||
<p>See <a href="https://doc.rust-lang.org/1.59.0/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/1.59.0/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-16" class="section-header"><a href="#panics-16">Panics</a></h5>
|
||
<p>Panics if <code>chunk_size</code> is 0.</p>
|
||
<h5 id="examples-38" class="section-header"><a href="#examples-38">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><div id="method.rchunks_exact_mut" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#1375" title="goto source code">[src]</a></div><a href="#method.rchunks_exact_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.rchunks_exact_mut" class="fnname">rchunks_exact_mut</a>(&mut self, chunk_size: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.RChunksExactMut.html" title="struct core::slice::iter::RChunksExactMut">RChunksExactMut</a><'_, T></h4></div></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 mutable 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>into_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/1.59.0/core/primitive.slice.html#method.chunks_mut"><code>chunks_mut</code></a>.</p>
|
||
<p>See <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.rchunks_mut"><code>rchunks_mut</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/1.59.0/core/primitive.slice.html#method.chunks_exact_mut"><code>chunks_exact_mut</code></a> for the same iterator but starting at the beginning
|
||
of the slice.</p>
|
||
<h5 id="panics-17" class="section-header"><a href="#panics-17">Panics</a></h5>
|
||
<p>Panics if <code>chunk_size</code> is 0.</p>
|
||
<h5 id="examples-39" class="section-header"><a href="#examples-39">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">&mut</span> [<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">count</span> <span class="op">=</span> <span class="number">1</span>;
|
||
|
||
<span class="kw">for</span> <span class="ident">chunk</span> <span class="kw">in</span> <span class="ident">v</span>.<span class="ident">rchunks_exact_mut</span>(<span class="number">2</span>) {
|
||
<span class="kw">for</span> <span class="ident">elem</span> <span class="kw">in</span> <span class="ident">chunk</span>.<span class="ident">iter_mut</span>() {
|
||
<span class="kw-2">*</span><span class="ident">elem</span> <span class="op">+</span><span class="op">=</span> <span class="ident">count</span>;
|
||
}
|
||
<span class="ident">count</span> <span class="op">+</span><span class="op">=</span> <span class="number">1</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, <span class="kw-2">&</span>[<span class="number">0</span>, <span class="number">2</span>, <span class="number">2</span>, <span class="number">1</span>, <span class="number">1</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.group_by" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#1418-1420" title="goto source code">[src]</a></div><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/1.59.0/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/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a>, </span></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_group_by</code>)</div></div></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-40" class="section-header"><a href="#examples-40">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><div id="method.group_by_mut" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#1463-1465" title="goto source code">[src]</a></div><a href="#method.group_by_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.group_by_mut" class="fnname">group_by_mut</a><F>(&mut self, pred: F) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.GroupByMut.html" title="struct core::slice::iter::GroupByMut">GroupByMut</a><'_, T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a>, </span></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_group_by</code>)</div></div></summary><div class="docblock"><p>Returns an iterator over the slice producing non-overlapping mutable
|
||
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-41" class="section-header"><a href="#examples-41">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">&mut</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_mut</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">&mut</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">&mut</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">&mut</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">&mut</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_mut</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">&mut</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">&mut</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">&mut</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><div id="method.split_at" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#1506" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[T]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a></h4></div></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-18" class="section-header"><a href="#panics-18">Panics</a></h5>
|
||
<p>Panics if <code>mid > len</code>.</p>
|
||
<h5 id="examples-42" class="section-header"><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">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><div id="method.split_at_mut" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#1537" title="goto source code">[src]</a></div><a href="#method.split_at_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.split_at_mut" class="fnname">split_at_mut</a>(&mut self, mid: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a></h4></div></summary><div class="docblock"><p>Divides one mutable 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-19" class="section-header"><a href="#panics-19">Panics</a></h5>
|
||
<p>Panics if <code>mid > len</code>.</p>
|
||
<h5 id="examples-43" class="section-header"><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="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">0</span>, <span class="number">3</span>, <span class="number">0</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_mut</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">0</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">right</span>, [<span class="number">3</span>, <span class="number">0</span>, <span class="number">5</span>, <span class="number">6</span>]);
|
||
<span class="ident">left</span>[<span class="number">1</span>] <span class="op">=</span> <span class="number">2</span>;
|
||
<span class="ident">right</span>[<span class="number">1</span>] <span class="op">=</span> <span class="number">4</span>;
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</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><div id="method.split_at_unchecked" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#1588" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[T]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a></h4></div><div 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></div></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/1.59.0/core/primitive.slice.html#method.split_at"><code>split_at</code></a>.</p>
|
||
<h5 id="safety-6" class="section-header"><a href="#safety-6">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-44" class="section-header"><a href="#examples-44">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><div id="method.split_at_mut_unchecked" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#1628" title="goto source code">[src]</a></div><a href="#method.split_at_mut_unchecked" class="anchor"></a><h4 class="code-header">pub unsafe fn <a href="#method.split_at_mut_unchecked" class="fnname">split_at_mut_unchecked</a>(<br> &mut self, <br> mid: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a><br>) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a></h4></div><div 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></div></summary><div class="docblock"><p>Divides one mutable 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/1.59.0/core/primitive.slice.html#method.split_at_mut"><code>split_at_mut</code></a>.</p>
|
||
<h5 id="safety-7" class="section-header"><a href="#safety-7">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-45" class="section-header"><a href="#examples-45">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="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">0</span>, <span class="number">3</span>, <span class="number">0</span>, <span class="number">5</span>, <span class="number">6</span>];
|
||
<span class="comment">// scoped to restrict the lifetime of the borrows</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_mut_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">0</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">right</span>, [<span class="number">3</span>, <span class="number">0</span>, <span class="number">5</span>, <span class="number">6</span>]);
|
||
<span class="ident">left</span>[<span class="number">1</span>] <span class="op">=</span> <span class="number">2</span>;
|
||
<span class="ident">right</span>[<span class="number">1</span>] <span class="op">=</span> <span class="number">4</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</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><div id="method.split_array_ref" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#1677" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a>>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a>&<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">; N]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>split_array</code>)</div></div></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-20" class="section-header"><a href="#panics-20">Panics</a></h5>
|
||
<p>Panics if <code>N > len</code>.</p>
|
||
<h5 id="examples-46" class="section-header"><a href="#examples-46">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><div id="method.split_array_mut" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#1709" title="goto source code">[src]</a></div><a href="#method.split_array_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.split_array_mut" class="fnname">split_array_mut</a><const N: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a>&mut <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">; N]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>split_array</code>)</div></div></summary><div class="docblock"><p>Divides one mutable 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-21" class="section-header"><a href="#panics-21">Panics</a></h5>
|
||
<p>Panics if <code>N > len</code>.</p>
|
||
<h5 id="examples-47" class="section-header"><a href="#examples-47">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="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&mut</span> [<span class="number">1</span>, <span class="number">0</span>, <span class="number">3</span>, <span class="number">0</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_mut</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">&mut</span> [<span class="number">1</span>, <span class="number">0</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">right</span>, [<span class="number">3</span>, <span class="number">0</span>, <span class="number">5</span>, <span class="number">6</span>]);
|
||
<span class="ident">left</span>[<span class="number">1</span>] <span class="op">=</span> <span class="number">2</span>;
|
||
<span class="ident">right</span>[<span class="number">1</span>] <span class="op">=</span> <span class="number">4</span>;
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</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><div id="method.rsplit_array_ref" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#1753" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a>>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[T]</a>, &<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">; N]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>split_array</code>)</div></div></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-22" class="section-header"><a href="#panics-22">Panics</a></h5>
|
||
<p>Panics if <code>N > len</code>.</p>
|
||
<h5 id="examples-48" class="section-header"><a href="#examples-48">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><div id="method.rsplit_array_mut" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#1786" title="goto source code">[src]</a></div><a href="#method.rsplit_array_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.rsplit_array_mut" class="fnname">rsplit_array_mut</a><const N: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a>, &mut <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">; N]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>split_array</code>)</div></div></summary><div class="docblock"><p>Divides one mutable 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>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-23" class="section-header"><a href="#panics-23">Panics</a></h5>
|
||
<p>Panics if <code>N > len</code>.</p>
|
||
<h5 id="examples-49" class="section-header"><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">split_array</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&mut</span> [<span class="number">1</span>, <span class="number">0</span>, <span class="number">3</span>, <span class="number">0</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_mut</span>::<span class="op"><</span><span class="number">4</span><span class="op">></span>();
|
||
<span class="macro">assert_eq!</span>(<span class="ident">left</span>, [<span class="number">1</span>, <span class="number">0</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">right</span>, <span class="kw-2">&mut</span> [<span class="number">3</span>, <span class="number">0</span>, <span class="number">5</span>, <span class="number">6</span>]);
|
||
<span class="ident">left</span>[<span class="number">1</span>] <span class="op">=</span> <span class="number">2</span>;
|
||
<span class="ident">right</span>[<span class="number">1</span>] <span class="op">=</span> <span class="number">4</span>;
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</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><div id="method.split" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#1835-1837" title="goto source code">[src]</a></div><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/1.59.0/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/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a>, </span></h4></div></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-50" class="section-header"><a href="#examples-50">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><div id="method.split_mut" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#1857-1859" title="goto source code">[src]</a></div><a href="#method.split_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.split_mut" class="fnname">split_mut</a><F>(&mut self, pred: F) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.SplitMut.html" title="struct core::slice::iter::SplitMut">SplitMut</a><'_, T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a>, </span></h4></div></summary><div class="docblock"><p>Returns an iterator over mutable subslices separated by elements that
|
||
match <code>pred</code>. The matched element is not contained in the subslices.</p>
|
||
<h5 id="examples-51" class="section-header"><a href="#examples-51">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="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">split_mut</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="ident">group</span>[<span class="number">0</span>] <span class="op">=</span> <span class="number">1</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="number">1</span>, <span class="number">40</span>, <span class="number">30</span>, <span class="number">1</span>, <span class="number">60</span>, <span class="number">1</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.split_inclusive" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#1893-1895" title="goto source code">[src]</a></div><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/1.59.0/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/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a>, </span></h4></div></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-52" class="section-header"><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">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><div id="method.split_inclusive_mut" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#1917-1919" title="goto source code">[src]</a></div><a href="#method.split_inclusive_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.split_inclusive_mut" class="fnname">split_inclusive_mut</a><F>(&mut self, pred: F) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.SplitInclusiveMut.html" title="struct core::slice::iter::SplitInclusiveMut">SplitInclusiveMut</a><'_, T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a>, </span></h4></div></summary><div class="docblock"><p>Returns an iterator over mutable subslices separated by elements that
|
||
match <code>pred</code>. The matched element is contained in the previous
|
||
subslice as a terminator.</p>
|
||
<h5 id="examples-53" class="section-header"><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="kw-2">mut</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">split_inclusive_mut</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="kw">let</span> <span class="ident">terminator_idx</span> <span class="op">=</span> <span class="ident">group</span>.<span class="ident">len</span>()<span class="op">-</span><span class="number">1</span>;
|
||
<span class="ident">group</span>[<span class="ident">terminator_idx</span>] <span class="op">=</span> <span class="number">1</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="number">10</span>, <span class="number">40</span>, <span class="number">1</span>, <span class="number">20</span>, <span class="number">1</span>, <span class="number">1</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.rsplit" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#1953-1955" title="goto source code">[src]</a></div><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/1.59.0/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/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a>, </span></h4></div></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-54" class="section-header"><a href="#examples-54">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><div id="method.rsplit_mut" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#1979-1981" title="goto source code">[src]</a></div><a href="#method.rsplit_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.rsplit_mut" class="fnname">rsplit_mut</a><F>(&mut self, pred: F) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.RSplitMut.html" title="struct core::slice::iter::RSplitMut">RSplitMut</a><'_, T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a>, </span></h4></div></summary><div class="docblock"><p>Returns an iterator over mutable 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-55" class="section-header"><a href="#examples-55">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="number">100</span>, <span class="number">400</span>, <span class="number">300</span>, <span class="number">200</span>, <span class="number">600</span>, <span class="number">500</span>];
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">count</span> <span class="op">=</span> <span class="number">0</span>;
|
||
<span class="kw">for</span> <span class="ident">group</span> <span class="kw">in</span> <span class="ident">v</span>.<span class="ident">rsplit_mut</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="ident">count</span> <span class="op">+</span><span class="op">=</span> <span class="number">1</span>;
|
||
<span class="ident">group</span>[<span class="number">0</span>] <span class="op">=</span> <span class="ident">count</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="number">3</span>, <span class="number">400</span>, <span class="number">300</span>, <span class="number">2</span>, <span class="number">600</span>, <span class="number">1</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.splitn" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#2007-2009" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a>, pred: F) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/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/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a>, </span></h4></div></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-56" class="section-header"><a href="#examples-56">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">"{:?}"</span>, <span class="ident">group</span>);
|
||
}</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.splitn_mut" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#2033-2035" title="goto source code">[src]</a></div><a href="#method.splitn_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.splitn_mut" class="fnname">splitn_mut</a><F>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>, pred: F) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.SplitNMut.html" title="struct core::slice::iter::SplitNMut">SplitNMut</a><'_, T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a>, </span></h4></div></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-57" class="section-header"><a href="#examples-57">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="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_mut</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="ident">group</span>[<span class="number">0</span>] <span class="op">=</span> <span class="number">1</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">v</span>, [<span class="number">1</span>, <span class="number">40</span>, <span class="number">30</span>, <span class="number">1</span>, <span class="number">60</span>, <span class="number">50</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.rsplitn" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#2062-2064" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a>, pred: F) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/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/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a>, </span></h4></div></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-58" class="section-header"><a href="#examples-58">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">"{:?}"</span>, <span class="ident">group</span>);
|
||
}</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.rsplitn_mut" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#2089-2091" title="goto source code">[src]</a></div><a href="#method.rsplitn_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.rsplitn_mut" class="fnname">rsplitn_mut</a><F>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>, pred: F) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.RSplitNMut.html" title="struct core::slice::iter::RSplitNMut">RSplitNMut</a><'_, T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a>, </span></h4></div></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-59" class="section-header"><a href="#examples-59">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">s</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">s</span>.<span class="ident">rsplitn_mut</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="ident">group</span>[<span class="number">0</span>] <span class="op">=</span> <span class="number">1</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(<span class="ident">s</span>, [<span class="number">1</span>, <span class="number">40</span>, <span class="number">30</span>, <span class="number">20</span>, <span class="number">60</span>, <span class="number">1</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.contains" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#2117-2119" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><T>, </span></h4></div></summary><div class="docblock"><p>Returns <code>true</code> if the slice contains an element with the given value.</p>
|
||
<h5 id="examples-60" class="section-header"><a href="#examples-60">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><div id="method.starts_with" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#2145-2147" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.slice.html">&[T]</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><T>, </span></h4></div></summary><div class="docblock"><p>Returns <code>true</code> if <code>needle</code> is a prefix of the slice.</p>
|
||
<h5 id="examples-61" class="section-header"><a href="#examples-61">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><div id="method.ends_with" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#2174-2176" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.slice.html">&[T]</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><T>, </span></h4></div></summary><div class="docblock"><p>Returns <code>true</code> if <code>needle</code> is a suffix of the slice.</p>
|
||
<h5 id="examples-62" class="section-header"><a href="#examples-62">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><div id="method.strip_prefix" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#2204-2206" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.reference.html">&</a>P) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[T]</a>> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/slice/trait.SlicePattern.html" title="trait core::slice::SlicePattern">SlicePattern</a><Item = T> + ?<a class="trait" href="https://doc.rust-lang.org/1.59.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,<br> T: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><T>, </span></h4></div></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-63" class="section-header"><a href="#examples-63">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><div id="method.strip_suffix" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#2238-2240" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.reference.html">&</a>P) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[T]</a>> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/slice/trait.SlicePattern.html" title="trait core::slice::SlicePattern">SlicePattern</a><Item = T> + ?<a class="trait" href="https://doc.rust-lang.org/1.59.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,<br> T: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><T>, </span></h4></div></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-64" class="section-header"><a href="#examples-64">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><div id="method.binary_search" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#2297-2299" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.reference.html">&</a>T) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>, </span></h4></div></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/1.59.0/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/1.59.0/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/1.59.0/core/primitive.slice.html#method.binary_search_by"><code>binary_search_by</code></a>, <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.binary_search_by_key"><code>binary_search_by_key</code></a>, and <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.partition_point"><code>partition_point</code></a>.</p>
|
||
<h5 id="examples-65" class="section-header"><a href="#examples-65">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><div id="method.binary_search_by" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#2346-2348" title="goto source code">[src]</a></div><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/1.59.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&'a </a>T) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>, </span></h4></div></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/1.59.0/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/1.59.0/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/1.59.0/core/primitive.slice.html#method.binary_search"><code>binary_search</code></a>, <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.binary_search_by_key"><code>binary_search_by_key</code></a>, and <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.partition_point"><code>partition_point</code></a>.</p>
|
||
<h5 id="examples-66" class="section-header"><a href="#examples-66">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><div id="method.binary_search_by_key" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#2424-2427" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.reference.html">&</a>B, <br> f: F<br>) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&'a </a>T) -> B,<br> B: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>, </span></h4></div></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/1.59.0/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/1.59.0/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/1.59.0/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/1.59.0/core/primitive.slice.html#method.binary_search"><code>binary_search</code></a>, <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.binary_search_by"><code>binary_search_by</code></a>, and <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.partition_point"><code>partition_point</code></a>.</p>
|
||
<h5 id="examples-67" class="section-header"><a href="#examples-67">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><div id="method.sort_unstable" class="method has-srclink"><div class="rightside"><span class="since" title="Stable since Rust version 1.20.0">1.20.0</span><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#2460-2462" title="goto source code">[src]</a></div><a href="#method.sort_unstable" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.sort_unstable" class="fnname">sort_unstable</a>(&mut self) <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>, </span></h4></div></summary><div class="docblock"><p>Sorts the slice, but might not preserve the order of equal elements.</p>
|
||
<p>This sort is unstable (i.e., may reorder equal elements), in-place
|
||
(i.e., does not allocate), and <em>O</em>(<em>n</em> * log(<em>n</em>)) worst-case.</p>
|
||
<h5 id="current-implementation" class="section-header"><a href="#current-implementation">Current implementation</a></h5>
|
||
<p>The current algorithm is based on <a href="https://github.com/orlp/pdqsort">pattern-defeating quicksort</a> by Orson Peters,
|
||
which combines the fast average case of randomized quicksort with the fast worst case of
|
||
heapsort, while achieving linear time on slices with certain patterns. It uses some
|
||
randomization to avoid degenerate cases, but with a fixed seed to always provide
|
||
deterministic behavior.</p>
|
||
<p>It is typically faster than stable sorting, except in a few special cases, e.g., when the
|
||
slice consists of several concatenated sorted sequences.</p>
|
||
<h5 id="examples-68" class="section-header"><a href="#examples-68">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="op">-</span><span class="number">5</span>, <span class="number">4</span>, <span class="number">1</span>, <span class="op">-</span><span class="number">3</span>, <span class="number">2</span>];
|
||
|
||
<span class="ident">v</span>.<span class="ident">sort_unstable</span>();
|
||
<span class="macro">assert!</span>(<span class="ident">v</span> <span class="op">==</span> [<span class="op">-</span><span class="number">5</span>, <span class="op">-</span><span class="number">3</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">4</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.sort_unstable_by" class="method has-srclink"><div class="rightside"><span class="since" title="Stable since Rust version 1.20.0">1.20.0</span><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#2515-2517" title="goto source code">[src]</a></div><a href="#method.sort_unstable_by" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.sort_unstable_by" class="fnname">sort_unstable_by</a><F>(&mut self, compare: F) <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>, </span></h4></div></summary><div class="docblock"><p>Sorts the slice with a comparator function, but might not preserve the order of equal
|
||
elements.</p>
|
||
<p>This sort is unstable (i.e., may reorder equal elements), in-place
|
||
(i.e., does not allocate), and <em>O</em>(<em>n</em> * log(<em>n</em>)) worst-case.</p>
|
||
<p>The comparator function must define a total ordering for the elements in the slice. If
|
||
the ordering is not total, the order of the elements is unspecified. An order is a
|
||
total order if it is (for all <code>a</code>, <code>b</code> and <code>c</code>):</p>
|
||
<ul>
|
||
<li>total and antisymmetric: exactly one of <code>a < b</code>, <code>a == b</code> or <code>a > b</code> is true, and</li>
|
||
<li>transitive, <code>a < b</code> and <code>b < c</code> implies <code>a < c</code>. The same must hold for both <code>==</code> and <code>></code>.</li>
|
||
</ul>
|
||
<p>For example, while <a href="https://doc.rust-lang.org/1.59.0/core/primitive.f64.html" title="f64"><code>f64</code></a> doesn’t implement <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html" title="Ord"><code>Ord</code></a> because <code>NaN != NaN</code>, we can use
|
||
<code>partial_cmp</code> as our sort function when we know the slice doesn’t contain a <code>NaN</code>.</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">floats</span> <span class="op">=</span> [<span class="number">5f64</span>, <span class="number">4.0</span>, <span class="number">1.0</span>, <span class="number">3.0</span>, <span class="number">2.0</span>];
|
||
<span class="ident">floats</span>.<span class="ident">sort_unstable_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="ident">partial_cmp</span>(<span class="ident">b</span>).<span class="ident">unwrap</span>());
|
||
<span class="macro">assert_eq!</span>(<span class="ident">floats</span>, [<span class="number">1.0</span>, <span class="number">2.0</span>, <span class="number">3.0</span>, <span class="number">4.0</span>, <span class="number">5.0</span>]);</code></pre></div>
|
||
<h5 id="current-implementation-1" class="section-header"><a href="#current-implementation-1">Current implementation</a></h5>
|
||
<p>The current algorithm is based on <a href="https://github.com/orlp/pdqsort">pattern-defeating quicksort</a> by Orson Peters,
|
||
which combines the fast average case of randomized quicksort with the fast worst case of
|
||
heapsort, while achieving linear time on slices with certain patterns. It uses some
|
||
randomization to avoid degenerate cases, but with a fixed seed to always provide
|
||
deterministic behavior.</p>
|
||
<p>It is typically faster than stable sorting, except in a few special cases, e.g., when the
|
||
slice consists of several concatenated sorted sequences.</p>
|
||
<h5 id="examples-69" class="section-header"><a href="#examples-69">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="number">5</span>, <span class="number">4</span>, <span class="number">1</span>, <span class="number">3</span>, <span class="number">2</span>];
|
||
<span class="ident">v</span>.<span class="ident">sort_unstable_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="ident">cmp</span>(<span class="ident">b</span>));
|
||
<span class="macro">assert!</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="comment">// reverse sorting</span>
|
||
<span class="ident">v</span>.<span class="ident">sort_unstable_by</span>(<span class="op">|</span><span class="ident">a</span>, <span class="ident">b</span><span class="op">|</span> <span class="ident">b</span>.<span class="ident">cmp</span>(<span class="ident">a</span>));
|
||
<span class="macro">assert!</span>(<span class="ident">v</span> <span class="op">==</span> [<span class="number">5</span>, <span class="number">4</span>, <span class="number">3</span>, <span class="number">2</span>, <span class="number">1</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.sort_unstable_by_key" class="method has-srclink"><div class="rightside"><span class="since" title="Stable since Rust version 1.20.0">1.20.0</span><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#2553-2556" title="goto source code">[src]</a></div><a href="#method.sort_unstable_by_key" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.sort_unstable_by_key" class="fnname">sort_unstable_by_key</a><K, F>(&mut self, f: F) <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> K,<br> K: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>, </span></h4></div></summary><div class="docblock"><p>Sorts the slice with a key extraction function, but might not preserve the order of equal
|
||
elements.</p>
|
||
<p>This sort is unstable (i.e., may reorder equal elements), in-place
|
||
(i.e., does not allocate), and <em>O</em>(m * <em>n</em> * log(<em>n</em>)) worst-case, where the key function is
|
||
<em>O</em>(<em>m</em>).</p>
|
||
<h5 id="current-implementation-2" class="section-header"><a href="#current-implementation-2">Current implementation</a></h5>
|
||
<p>The current algorithm is based on <a href="https://github.com/orlp/pdqsort">pattern-defeating quicksort</a> by Orson Peters,
|
||
which combines the fast average case of randomized quicksort with the fast worst case of
|
||
heapsort, while achieving linear time on slices with certain patterns. It uses some
|
||
randomization to avoid degenerate cases, but with a fixed seed to always provide
|
||
deterministic behavior.</p>
|
||
<p>Due to its key calling strategy, <a href="#method.sort_unstable_by_key"><code>sort_unstable_by_key</code></a>
|
||
is likely to be slower than <a href="#method.sort_by_cached_key"><code>sort_by_cached_key</code></a> in
|
||
cases where the key function is expensive.</p>
|
||
<h5 id="examples-70" class="section-header"><a href="#examples-70">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="op">-</span><span class="number">5i32</span>, <span class="number">4</span>, <span class="number">1</span>, <span class="op">-</span><span class="number">3</span>, <span class="number">2</span>];
|
||
|
||
<span class="ident">v</span>.<span class="ident">sort_unstable_by_key</span>(<span class="op">|</span><span class="ident">k</span><span class="op">|</span> <span class="ident">k</span>.<span class="ident">abs</span>());
|
||
<span class="macro">assert!</span>(<span class="ident">v</span> <span class="op">==</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="op">-</span><span class="number">3</span>, <span class="number">4</span>, <span class="op">-</span><span class="number">5</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.partition_at_index" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#2565-2567" title="goto source code">[src]</a></div><a href="#method.partition_at_index" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.partition_at_index" class="fnname">partition_at_index</a>(<br> &mut self, <br> index: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a><br>) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&mut </a>T, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>, </span></h4></div><div class="item-info"><div class="stab deprecated"><span class="emoji">👎</span> Deprecated since 1.49.0: <p>use the select_nth_unstable() instead</p>
|
||
</div><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_partition_at_index</code>)</div></div></summary><div class="docblock"><p>Reorder the slice such that the element at <code>index</code> is at its final sorted position.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.partition_at_index_by" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#2577-2583" title="goto source code">[src]</a></div><a href="#method.partition_at_index_by" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.partition_at_index_by" class="fnname">partition_at_index_by</a><F>(<br> &mut self, <br> index: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>, <br> compare: F<br>) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&mut </a>T, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>, </span></h4></div><div class="item-info"><div class="stab deprecated"><span class="emoji">👎</span> Deprecated since 1.49.0: <p>use select_nth_unstable_by() instead</p>
|
||
</div><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_partition_at_index</code>)</div></div></summary><div class="docblock"><p>Reorder the slice with a comparator function such that the element at <code>index</code> is at its
|
||
final sorted position.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.partition_at_index_by_key" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#2593-2600" title="goto source code">[src]</a></div><a href="#method.partition_at_index_by_key" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.partition_at_index_by_key" class="fnname">partition_at_index_by_key</a><K, F>(<br> &mut self, <br> index: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>, <br> f: F<br>) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&mut </a>T, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> K,<br> K: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>, </span></h4></div><div class="item-info"><div class="stab deprecated"><span class="emoji">👎</span> Deprecated since 1.49.0: <p>use the select_nth_unstable_by_key() instead</p>
|
||
</div><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_partition_at_index</code>)</div></div></summary><div class="docblock"><p>Reorder the slice with a key extraction function such that the element at <code>index</code> is at its
|
||
final sorted position.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.select_nth_unstable" class="method has-srclink"><div class="rightside"><span class="since" title="Stable since Rust version 1.49.0">1.49.0</span><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#2643-2645" title="goto source code">[src]</a></div><a href="#method.select_nth_unstable" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.select_nth_unstable" class="fnname">select_nth_unstable</a>(<br> &mut self, <br> index: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a><br>) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&mut </a>T, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>, </span></h4></div></summary><div class="docblock"><p>Reorder the slice such that the element at <code>index</code> is at its final sorted position.</p>
|
||
<p>This reordering has the additional property that any value at position <code>i < index</code> will be
|
||
less than or equal to any value at a position <code>j > index</code>. Additionally, this reordering is
|
||
unstable (i.e. any number of equal elements may end up at position <code>index</code>), in-place
|
||
(i.e. does not allocate), and <em>O</em>(<em>n</em>) worst-case. This function is also/ known as “kth
|
||
element” in other libraries. It returns a triplet of the following values: all elements less
|
||
than the one at the given index, the value at the given index, and all elements greater than
|
||
the one at the given index.</p>
|
||
<h5 id="current-implementation-3" class="section-header"><a href="#current-implementation-3">Current implementation</a></h5>
|
||
<p>The current algorithm is based on the quickselect portion of the same quicksort algorithm
|
||
used for <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.sort_unstable"><code>sort_unstable</code></a>.</p>
|
||
<h5 id="panics-24" class="section-header"><a href="#panics-24">Panics</a></h5>
|
||
<p>Panics when <code>index >= len()</code>, meaning it always panics on empty slices.</p>
|
||
<h5 id="examples-71" class="section-header"><a href="#examples-71">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="op">-</span><span class="number">5i32</span>, <span class="number">4</span>, <span class="number">1</span>, <span class="op">-</span><span class="number">3</span>, <span class="number">2</span>];
|
||
|
||
<span class="comment">// Find the median</span>
|
||
<span class="ident">v</span>.<span class="ident">select_nth_unstable</span>(<span class="number">2</span>);
|
||
|
||
<span class="comment">// We are only guaranteed the slice will be one of the following, based on the way we sort</span>
|
||
<span class="comment">// about the specified index.</span>
|
||
<span class="macro">assert!</span>(<span class="ident">v</span> <span class="op">==</span> [<span class="op">-</span><span class="number">3</span>, <span class="op">-</span><span class="number">5</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">4</span>] <span class="op">|</span><span class="op">|</span>
|
||
<span class="ident">v</span> <span class="op">==</span> [<span class="op">-</span><span class="number">5</span>, <span class="op">-</span><span class="number">3</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">4</span>] <span class="op">|</span><span class="op">|</span>
|
||
<span class="ident">v</span> <span class="op">==</span> [<span class="op">-</span><span class="number">3</span>, <span class="op">-</span><span class="number">5</span>, <span class="number">1</span>, <span class="number">4</span>, <span class="number">2</span>] <span class="op">|</span><span class="op">|</span>
|
||
<span class="ident">v</span> <span class="op">==</span> [<span class="op">-</span><span class="number">5</span>, <span class="op">-</span><span class="number">3</span>, <span class="number">1</span>, <span class="number">4</span>, <span class="number">2</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.select_nth_unstable_by" class="method has-srclink"><div class="rightside"><span class="since" title="Stable since Rust version 1.49.0">1.49.0</span><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#2691-2697" title="goto source code">[src]</a></div><a href="#method.select_nth_unstable_by" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.select_nth_unstable_by" class="fnname">select_nth_unstable_by</a><F>(<br> &mut self, <br> index: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>, <br> compare: F<br>) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&mut </a>T, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>, </span></h4></div></summary><div class="docblock"><p>Reorder the slice with a comparator function such that the element at <code>index</code> is at its
|
||
final sorted position.</p>
|
||
<p>This reordering has the additional property that any value at position <code>i < index</code> will be
|
||
less than or equal to any value at a position <code>j > index</code> using the comparator function.
|
||
Additionally, this reordering is unstable (i.e. any number of equal elements may end up at
|
||
position <code>index</code>), in-place (i.e. does not allocate), and <em>O</em>(<em>n</em>) worst-case. This function
|
||
is also known as “kth element” in other libraries. It returns a triplet of the following
|
||
values: all elements less than the one at the given index, the value at the given index,
|
||
and all elements greater than the one at the given index, using the provided comparator
|
||
function.</p>
|
||
<h5 id="current-implementation-4" class="section-header"><a href="#current-implementation-4">Current implementation</a></h5>
|
||
<p>The current algorithm is based on the quickselect portion of the same quicksort algorithm
|
||
used for <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.sort_unstable"><code>sort_unstable</code></a>.</p>
|
||
<h5 id="panics-25" class="section-header"><a href="#panics-25">Panics</a></h5>
|
||
<p>Panics when <code>index >= len()</code>, meaning it always panics on empty slices.</p>
|
||
<h5 id="examples-72" class="section-header"><a href="#examples-72">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="op">-</span><span class="number">5i32</span>, <span class="number">4</span>, <span class="number">1</span>, <span class="op">-</span><span class="number">3</span>, <span class="number">2</span>];
|
||
|
||
<span class="comment">// Find the median as if the slice were sorted in descending order.</span>
|
||
<span class="ident">v</span>.<span class="ident">select_nth_unstable_by</span>(<span class="number">2</span>, <span class="op">|</span><span class="ident">a</span>, <span class="ident">b</span><span class="op">|</span> <span class="ident">b</span>.<span class="ident">cmp</span>(<span class="ident">a</span>));
|
||
|
||
<span class="comment">// We are only guaranteed the slice will be one of the following, based on the way we sort</span>
|
||
<span class="comment">// about the specified index.</span>
|
||
<span class="macro">assert!</span>(<span class="ident">v</span> <span class="op">==</span> [<span class="number">2</span>, <span class="number">4</span>, <span class="number">1</span>, <span class="op">-</span><span class="number">5</span>, <span class="op">-</span><span class="number">3</span>] <span class="op">|</span><span class="op">|</span>
|
||
<span class="ident">v</span> <span class="op">==</span> [<span class="number">2</span>, <span class="number">4</span>, <span class="number">1</span>, <span class="op">-</span><span class="number">3</span>, <span class="op">-</span><span class="number">5</span>] <span class="op">|</span><span class="op">|</span>
|
||
<span class="ident">v</span> <span class="op">==</span> [<span class="number">4</span>, <span class="number">2</span>, <span class="number">1</span>, <span class="op">-</span><span class="number">5</span>, <span class="op">-</span><span class="number">3</span>] <span class="op">|</span><span class="op">|</span>
|
||
<span class="ident">v</span> <span class="op">==</span> [<span class="number">4</span>, <span class="number">2</span>, <span class="number">1</span>, <span class="op">-</span><span class="number">3</span>, <span class="op">-</span><span class="number">5</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.select_nth_unstable_by_key" class="method has-srclink"><div class="rightside"><span class="since" title="Stable since Rust version 1.49.0">1.49.0</span><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#2743-2750" title="goto source code">[src]</a></div><a href="#method.select_nth_unstable_by_key" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.select_nth_unstable_by_key" class="fnname">select_nth_unstable_by_key</a><K, F>(<br> &mut self, <br> index: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>, <br> f: F<br>) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&mut </a>T, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> K,<br> K: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>, </span></h4></div></summary><div class="docblock"><p>Reorder the slice with a key extraction function such that the element at <code>index</code> is at its
|
||
final sorted position.</p>
|
||
<p>This reordering has the additional property that any value at position <code>i < index</code> will be
|
||
less than or equal to any value at a position <code>j > index</code> using the key extraction function.
|
||
Additionally, this reordering is unstable (i.e. any number of equal elements may end up at
|
||
position <code>index</code>), in-place (i.e. does not allocate), and <em>O</em>(<em>n</em>) worst-case. This function
|
||
is also known as “kth element” in other libraries. It returns a triplet of the following
|
||
values: all elements less than the one at the given index, the value at the given index, and
|
||
all elements greater than the one at the given index, using the provided key extraction
|
||
function.</p>
|
||
<h5 id="current-implementation-5" class="section-header"><a href="#current-implementation-5">Current implementation</a></h5>
|
||
<p>The current algorithm is based on the quickselect portion of the same quicksort algorithm
|
||
used for <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.sort_unstable"><code>sort_unstable</code></a>.</p>
|
||
<h5 id="panics-26" class="section-header"><a href="#panics-26">Panics</a></h5>
|
||
<p>Panics when <code>index >= len()</code>, meaning it always panics on empty slices.</p>
|
||
<h5 id="examples-73" class="section-header"><a href="#examples-73">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="op">-</span><span class="number">5i32</span>, <span class="number">4</span>, <span class="number">1</span>, <span class="op">-</span><span class="number">3</span>, <span class="number">2</span>];
|
||
|
||
<span class="comment">// Return the median as if the array were sorted according to absolute value.</span>
|
||
<span class="ident">v</span>.<span class="ident">select_nth_unstable_by_key</span>(<span class="number">2</span>, <span class="op">|</span><span class="ident">a</span><span class="op">|</span> <span class="ident">a</span>.<span class="ident">abs</span>());
|
||
|
||
<span class="comment">// We are only guaranteed the slice will be one of the following, based on the way we sort</span>
|
||
<span class="comment">// about the specified index.</span>
|
||
<span class="macro">assert!</span>(<span class="ident">v</span> <span class="op">==</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="op">-</span><span class="number">3</span>, <span class="number">4</span>, <span class="op">-</span><span class="number">5</span>] <span class="op">|</span><span class="op">|</span>
|
||
<span class="ident">v</span> <span class="op">==</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="op">-</span><span class="number">3</span>, <span class="op">-</span><span class="number">5</span>, <span class="number">4</span>] <span class="op">|</span><span class="op">|</span>
|
||
<span class="ident">v</span> <span class="op">==</span> [<span class="number">2</span>, <span class="number">1</span>, <span class="op">-</span><span class="number">3</span>, <span class="number">4</span>, <span class="op">-</span><span class="number">5</span>] <span class="op">|</span><span class="op">|</span>
|
||
<span class="ident">v</span> <span class="op">==</span> [<span class="number">2</span>, <span class="number">1</span>, <span class="op">-</span><span class="number">3</span>, <span class="op">-</span><span class="number">5</span>, <span class="number">4</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.partition_dedup" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#2778-2780" title="goto source code">[src]</a></div><a href="#method.partition_dedup" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.partition_dedup" class="fnname">partition_dedup</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><T>, </span></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_partition_dedup</code>)</div></div></summary><div class="docblock"><p>Moves all consecutive repeated elements to the end of the slice according to the
|
||
<a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialEq.html" title="PartialEq"><code>PartialEq</code></a> trait implementation.</p>
|
||
<p>Returns two slices. The first contains no consecutive repeated elements.
|
||
The second contains all the duplicates in no specified order.</p>
|
||
<p>If the slice is sorted, the first returned slice contains no duplicates.</p>
|
||
<h5 id="examples-74" class="section-header"><a href="#examples-74">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_partition_dedup</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">slice</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">3</span>, <span class="number">2</span>, <span class="number">1</span>, <span class="number">1</span>];
|
||
|
||
<span class="kw">let</span> (<span class="ident">dedup</span>, <span class="ident">duplicates</span>) <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">partition_dedup</span>();
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">dedup</span>, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">2</span>, <span class="number">1</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">duplicates</span>, [<span class="number">2</span>, <span class="number">3</span>, <span class="number">1</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.partition_dedup_by" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#2812-2814" title="goto source code">[src]</a></div><a href="#method.partition_dedup_by" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.partition_dedup_by" class="fnname">partition_dedup_by</a><F>(&mut self, same_bucket: F) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&mut </a>T, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&mut </a>T) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a>, </span></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_partition_dedup</code>)</div></div></summary><div class="docblock"><p>Moves all but the first of consecutive elements to the end of the slice satisfying
|
||
a given equality relation.</p>
|
||
<p>Returns two slices. The first contains no consecutive repeated elements.
|
||
The second contains all the duplicates in no specified order.</p>
|
||
<p>The <code>same_bucket</code> function is passed references to two elements from the slice and
|
||
must determine if the elements compare equal. The elements are passed in opposite order
|
||
from their order in the slice, so if <code>same_bucket(a, b)</code> returns <code>true</code>, <code>a</code> is moved
|
||
at the end of the slice.</p>
|
||
<p>If the slice is sorted, the first returned slice contains no duplicates.</p>
|
||
<h5 id="examples-75" class="section-header"><a href="#examples-75">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_partition_dedup</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">slice</span> <span class="op">=</span> [<span class="string">"foo"</span>, <span class="string">"Foo"</span>, <span class="string">"BAZ"</span>, <span class="string">"Bar"</span>, <span class="string">"bar"</span>, <span class="string">"baz"</span>, <span class="string">"BAZ"</span>];
|
||
|
||
<span class="kw">let</span> (<span class="ident">dedup</span>, <span class="ident">duplicates</span>) <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">partition_dedup_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="ident">eq_ignore_ascii_case</span>(<span class="ident">b</span>));
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">dedup</span>, [<span class="string">"foo"</span>, <span class="string">"BAZ"</span>, <span class="string">"Bar"</span>, <span class="string">"baz"</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">duplicates</span>, [<span class="string">"bar"</span>, <span class="string">"Foo"</span>, <span class="string">"BAZ"</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.partition_dedup_by_key" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#2938-2941" title="goto source code">[src]</a></div><a href="#method.partition_dedup_by_key" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.partition_dedup_by_key" class="fnname">partition_dedup_by_key</a><K, F>(&mut self, key: F) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&mut </a>T) -> K,<br> K: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><K>, </span></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_partition_dedup</code>)</div></div></summary><div class="docblock"><p>Moves all but the first of consecutive elements to the end of the slice that resolve
|
||
to the same key.</p>
|
||
<p>Returns two slices. The first contains no consecutive repeated elements.
|
||
The second contains all the duplicates in no specified order.</p>
|
||
<p>If the slice is sorted, the first returned slice contains no duplicates.</p>
|
||
<h5 id="examples-76" class="section-header"><a href="#examples-76">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_partition_dedup</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">slice</span> <span class="op">=</span> [<span class="number">10</span>, <span class="number">20</span>, <span class="number">21</span>, <span class="number">30</span>, <span class="number">30</span>, <span class="number">20</span>, <span class="number">11</span>, <span class="number">13</span>];
|
||
|
||
<span class="kw">let</span> (<span class="ident">dedup</span>, <span class="ident">duplicates</span>) <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">partition_dedup_by_key</span>(<span class="op">|</span><span class="ident">i</span><span class="op">|</span> <span class="kw-2">*</span><span class="ident">i</span> <span class="op">/</span> <span class="number">10</span>);
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">dedup</span>, [<span class="number">10</span>, <span class="number">20</span>, <span class="number">30</span>, <span class="number">20</span>, <span class="number">11</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">duplicates</span>, [<span class="number">21</span>, <span class="number">30</span>, <span class="number">13</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.rotate_left" class="method has-srclink"><div class="rightside"><span class="since" title="Stable since Rust version 1.26.0">1.26.0</span><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#2977" title="goto source code">[src]</a></div><a href="#method.rotate_left" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.rotate_left" class="fnname">rotate_left</a>(&mut self, mid: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>)</h4></div></summary><div class="docblock"><p>Rotates the slice in-place such that the first <code>mid</code> elements of the
|
||
slice move to the end while the last <code>self.len() - mid</code> elements move to
|
||
the front. After calling <code>rotate_left</code>, the element previously at index
|
||
<code>mid</code> will become the first element in the slice.</p>
|
||
<h5 id="panics-27" class="section-header"><a href="#panics-27">Panics</a></h5>
|
||
<p>This function will panic if <code>mid</code> is greater than the length of the
|
||
slice. Note that <code>mid == self.len()</code> does <em>not</em> panic and is a no-op
|
||
rotation.</p>
|
||
<h5 id="complexity" class="section-header"><a href="#complexity">Complexity</a></h5>
|
||
<p>Takes linear (in <code>self.len()</code>) time.</p>
|
||
<h5 id="examples-77" class="section-header"><a href="#examples-77">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">a</span> <span class="op">=</span> [<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>, <span class="string">'e'</span>, <span class="string">'f'</span>];
|
||
<span class="ident">a</span>.<span class="ident">rotate_left</span>(<span class="number">2</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">a</span>, [<span class="string">'c'</span>, <span class="string">'d'</span>, <span class="string">'e'</span>, <span class="string">'f'</span>, <span class="string">'a'</span>, <span class="string">'b'</span>]);</code></pre></div>
|
||
<p>Rotating a subslice:</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">a</span> <span class="op">=</span> [<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>, <span class="string">'e'</span>, <span class="string">'f'</span>];
|
||
<span class="ident">a</span>[<span class="number">1</span>..<span class="number">5</span>].<span class="ident">rotate_left</span>(<span class="number">1</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">a</span>, [<span class="string">'a'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>, <span class="string">'e'</span>, <span class="string">'b'</span>, <span class="string">'f'</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.rotate_right" class="method has-srclink"><div class="rightside"><span class="since" title="Stable since Rust version 1.26.0">1.26.0</span><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#3020" title="goto source code">[src]</a></div><a href="#method.rotate_right" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.rotate_right" class="fnname">rotate_right</a>(&mut self, k: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>)</h4></div></summary><div class="docblock"><p>Rotates the slice in-place such that the first <code>self.len() - k</code>
|
||
elements of the slice move to the end while the last <code>k</code> elements move
|
||
to the front. After calling <code>rotate_right</code>, the element previously at
|
||
index <code>self.len() - k</code> will become the first element in the slice.</p>
|
||
<h5 id="panics-28" class="section-header"><a href="#panics-28">Panics</a></h5>
|
||
<p>This function will panic if <code>k</code> is greater than the length of the
|
||
slice. Note that <code>k == self.len()</code> does <em>not</em> panic and is a no-op
|
||
rotation.</p>
|
||
<h5 id="complexity-1" class="section-header"><a href="#complexity-1">Complexity</a></h5>
|
||
<p>Takes linear (in <code>self.len()</code>) time.</p>
|
||
<h5 id="examples-78" class="section-header"><a href="#examples-78">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">a</span> <span class="op">=</span> [<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>, <span class="string">'e'</span>, <span class="string">'f'</span>];
|
||
<span class="ident">a</span>.<span class="ident">rotate_right</span>(<span class="number">2</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">a</span>, [<span class="string">'e'</span>, <span class="string">'f'</span>, <span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>]);</code></pre></div>
|
||
<p>Rotate a subslice:</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">a</span> <span class="op">=</span> [<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>, <span class="string">'e'</span>, <span class="string">'f'</span>];
|
||
<span class="ident">a</span>[<span class="number">1</span>..<span class="number">5</span>].<span class="ident">rotate_right</span>(<span class="number">1</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">a</span>, [<span class="string">'a'</span>, <span class="string">'e'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>, <span class="string">'f'</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.fill" class="method has-srclink"><div class="rightside"><span class="since" title="Stable since Rust version 1.50.0">1.50.0</span><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#3043-3045" title="goto source code">[src]</a></div><a href="#method.fill" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.fill" class="fnname">fill</a>(&mut self, value: T) <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, </span></h4></div></summary><div class="docblock"><p>Fills <code>self</code> with elements by cloning <code>value</code>.</p>
|
||
<h5 id="examples-79" class="section-header"><a href="#examples-79">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">buf</span> <span class="op">=</span> <span class="macro">vec!</span>[<span class="number">0</span>; <span class="number">10</span>];
|
||
<span class="ident">buf</span>.<span class="ident">fill</span>(<span class="number">1</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">buf</span>, <span class="macro">vec!</span>[<span class="number">1</span>; <span class="number">10</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.fill_with" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#3068-3070" title="goto source code">[src]</a></div><a href="#method.fill_with" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.fill_with" class="fnname">fill_with</a><F>(&mut self, f: F) <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>() -> T, </span></h4></div></summary><div class="docblock"><p>Fills <code>self</code> with elements returned by calling a closure repeatedly.</p>
|
||
<p>This method uses a closure to create new values. If you’d rather
|
||
<a href="https://doc.rust-lang.org/1.59.0/core/clone/trait.Clone.html" title="Clone"><code>Clone</code></a> a given value, use <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.fill"><code>fill</code></a>. If you want to use the <a href="https://doc.rust-lang.org/1.59.0/core/default/trait.Default.html" title="Default"><code>Default</code></a>
|
||
trait to generate values, you can pass <a href="https://doc.rust-lang.org/1.59.0/core/default/trait.Default.html#tymethod.default" title="Default::default"><code>Default::default</code></a> as the
|
||
argument.</p>
|
||
<h5 id="examples-80" class="section-header"><a href="#examples-80">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">buf</span> <span class="op">=</span> <span class="macro">vec!</span>[<span class="number">1</span>; <span class="number">10</span>];
|
||
<span class="ident">buf</span>.<span class="ident">fill_with</span>(<span class="ident">Default::default</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">buf</span>, <span class="macro">vec!</span>[<span class="number">0</span>; <span class="number">10</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.clone_from_slice" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#3131-3133" title="goto source code">[src]</a></div><a href="#method.clone_from_slice" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.clone_from_slice" class="fnname">clone_from_slice</a>(&mut self, src: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[T]</a>) <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, </span></h4></div></summary><div class="docblock"><p>Copies the elements from <code>src</code> into <code>self</code>.</p>
|
||
<p>The length of <code>src</code> must be the same as <code>self</code>.</p>
|
||
<h5 id="panics-29" class="section-header"><a href="#panics-29">Panics</a></h5>
|
||
<p>This function will panic if the two slices have different lengths.</p>
|
||
<h5 id="examples-81" class="section-header"><a href="#examples-81">Examples</a></h5>
|
||
<p>Cloning two elements from a slice into another:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">src</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="kw">let</span> <span class="kw-2">mut</span> <span class="ident">dst</span> <span class="op">=</span> [<span class="number">0</span>, <span class="number">0</span>];
|
||
|
||
<span class="comment">// Because the slices have to be the same length,</span>
|
||
<span class="comment">// we slice the source slice from four elements</span>
|
||
<span class="comment">// to two. It will panic if we don't do this.</span>
|
||
<span class="ident">dst</span>.<span class="ident">clone_from_slice</span>(<span class="kw-2">&</span><span class="ident">src</span>[<span class="number">2</span>..]);
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">src</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">dst</span>, [<span class="number">3</span>, <span class="number">4</span>]);</code></pre></div>
|
||
<p>Rust enforces that there can only be one mutable reference with no
|
||
immutable references to a particular piece of data in a particular
|
||
scope. Because of this, attempting to use <code>clone_from_slice</code> on a
|
||
single slice will result in a compile failure:</p>
|
||
|
||
<div class='information'><div class='tooltip compile_fail'>ⓘ</div></div><div class="example-wrap"><pre class="rust rust-example-rendered compile_fail"><code><span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">slice</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="ident">slice</span>[..<span class="number">2</span>].<span class="ident">clone_from_slice</span>(<span class="kw-2">&</span><span class="ident">slice</span>[<span class="number">3</span>..]); <span class="comment">// compile fail!</span></code></pre></div>
|
||
<p>To work around this, we can use <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.split_at_mut"><code>split_at_mut</code></a> to create two distinct
|
||
sub-slices from a slice:</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">slice</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="kw">let</span> (<span class="ident">left</span>, <span class="ident">right</span>) <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">split_at_mut</span>(<span class="number">2</span>);
|
||
<span class="ident">left</span>.<span class="ident">clone_from_slice</span>(<span class="kw-2">&</span><span class="ident">right</span>[<span class="number">1</span>..]);
|
||
}
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">slice</span>, [<span class="number">4</span>, <span class="number">5</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.copy_from_slice" class="method has-srclink"><div class="rightside"><span class="since" title="Stable since Rust version 1.9.0">1.9.0</span><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#3195-3197" title="goto source code">[src]</a></div><a href="#method.copy_from_slice" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.copy_from_slice" class="fnname">copy_from_slice</a>(&mut self, src: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[T]</a>) <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/marker/trait.Copy.html" title="trait core::marker::Copy">Copy</a>, </span></h4></div></summary><div class="docblock"><p>Copies all elements from <code>src</code> into <code>self</code>, using a memcpy.</p>
|
||
<p>The length of <code>src</code> must be the same as <code>self</code>.</p>
|
||
<p>If <code>T</code> does not implement <code>Copy</code>, use <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.clone_from_slice"><code>clone_from_slice</code></a>.</p>
|
||
<h5 id="panics-30" class="section-header"><a href="#panics-30">Panics</a></h5>
|
||
<p>This function will panic if the two slices have different lengths.</p>
|
||
<h5 id="examples-82" class="section-header"><a href="#examples-82">Examples</a></h5>
|
||
<p>Copying two elements from a slice into another:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let</span> <span class="ident">src</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="kw">let</span> <span class="kw-2">mut</span> <span class="ident">dst</span> <span class="op">=</span> [<span class="number">0</span>, <span class="number">0</span>];
|
||
|
||
<span class="comment">// Because the slices have to be the same length,</span>
|
||
<span class="comment">// we slice the source slice from four elements</span>
|
||
<span class="comment">// to two. It will panic if we don't do this.</span>
|
||
<span class="ident">dst</span>.<span class="ident">copy_from_slice</span>(<span class="kw-2">&</span><span class="ident">src</span>[<span class="number">2</span>..]);
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">src</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">dst</span>, [<span class="number">3</span>, <span class="number">4</span>]);</code></pre></div>
|
||
<p>Rust enforces that there can only be one mutable reference with no
|
||
immutable references to a particular piece of data in a particular
|
||
scope. Because of this, attempting to use <code>copy_from_slice</code> on a
|
||
single slice will result in a compile failure:</p>
|
||
|
||
<div class='information'><div class='tooltip compile_fail'>ⓘ</div></div><div class="example-wrap"><pre class="rust rust-example-rendered compile_fail"><code><span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">slice</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="ident">slice</span>[..<span class="number">2</span>].<span class="ident">copy_from_slice</span>(<span class="kw-2">&</span><span class="ident">slice</span>[<span class="number">3</span>..]); <span class="comment">// compile fail!</span></code></pre></div>
|
||
<p>To work around this, we can use <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.split_at_mut"><code>split_at_mut</code></a> to create two distinct
|
||
sub-slices from a slice:</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">slice</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="kw">let</span> (<span class="ident">left</span>, <span class="ident">right</span>) <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">split_at_mut</span>(<span class="number">2</span>);
|
||
<span class="ident">left</span>.<span class="ident">copy_from_slice</span>(<span class="kw-2">&</span><span class="ident">right</span>[<span class="number">1</span>..]);
|
||
}
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">slice</span>, [<span class="number">4</span>, <span class="number">5</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.copy_within" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#3249-3251" title="goto source code">[src]</a></div><a href="#method.copy_within" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.copy_within" class="fnname">copy_within</a><R>(&mut self, src: R, dest: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>) <span class="where fmt-newline">where<br> R: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/range/trait.RangeBounds.html" title="trait core::ops::range::RangeBounds">RangeBounds</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>>,<br> T: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/marker/trait.Copy.html" title="trait core::marker::Copy">Copy</a>, </span></h4></div></summary><div class="docblock"><p>Copies elements from one part of the slice to another part of itself,
|
||
using a memmove.</p>
|
||
<p><code>src</code> is the range within <code>self</code> to copy from. <code>dest</code> is the starting
|
||
index of the range within <code>self</code> to copy to, which will have the same
|
||
length as <code>src</code>. The two ranges may overlap. The ends of the two ranges
|
||
must be less than or equal to <code>self.len()</code>.</p>
|
||
<h5 id="panics-31" class="section-header"><a href="#panics-31">Panics</a></h5>
|
||
<p>This function will panic if either range exceeds the end of the slice,
|
||
or if the end of <code>src</code> is before the start.</p>
|
||
<h5 id="examples-83" class="section-header"><a href="#examples-83">Examples</a></h5>
|
||
<p>Copying four bytes within a slice:</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">bytes</span> <span class="op">=</span> <span class="kw-2">*</span><span class="string">b"Hello, World!"</span>;
|
||
|
||
<span class="ident">bytes</span>.<span class="ident">copy_within</span>(<span class="number">1</span>..<span class="number">5</span>, <span class="number">8</span>);
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span><span class="ident">bytes</span>, <span class="string">b"Hello, Wello!"</span>);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.swap_with_slice" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#3316" title="goto source code">[src]</a></div><a href="#method.swap_with_slice" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.swap_with_slice" class="fnname">swap_with_slice</a>(&mut self, other: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a>)</h4></div></summary><div class="docblock"><p>Swaps all elements in <code>self</code> with those in <code>other</code>.</p>
|
||
<p>The length of <code>other</code> must be the same as <code>self</code>.</p>
|
||
<h5 id="panics-32" class="section-header"><a href="#panics-32">Panics</a></h5>
|
||
<p>This function will panic if the two slices have different lengths.</p>
|
||
<h5 id="example-2" class="section-header"><a href="#example-2">Example</a></h5>
|
||
<p>Swapping two elements across slices:</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">slice1</span> <span class="op">=</span> [<span class="number">0</span>, <span class="number">0</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">slice2</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="ident">slice1</span>.<span class="ident">swap_with_slice</span>(<span class="kw-2">&mut</span> <span class="ident">slice2</span>[<span class="number">2</span>..]);
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">slice1</span>, [<span class="number">3</span>, <span class="number">4</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">slice2</span>, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">0</span>, <span class="number">0</span>]);</code></pre></div>
|
||
<p>Rust enforces that there can only be one mutable reference to a
|
||
particular piece of data in a particular scope. Because of this,
|
||
attempting to use <code>swap_with_slice</code> on a single slice will result in
|
||
a compile failure:</p>
|
||
|
||
<div class='information'><div class='tooltip compile_fail'>ⓘ</div></div><div class="example-wrap"><pre class="rust rust-example-rendered compile_fail"><code><span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">slice</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="ident">slice</span>[..<span class="number">2</span>].<span class="ident">swap_with_slice</span>(<span class="kw-2">&mut</span> <span class="ident">slice</span>[<span class="number">3</span>..]); <span class="comment">// compile fail!</span></code></pre></div>
|
||
<p>To work around this, we can use <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.split_at_mut"><code>split_at_mut</code></a> to create two distinct
|
||
mutable sub-slices from a slice:</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">slice</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="kw">let</span> (<span class="ident">left</span>, <span class="ident">right</span>) <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">split_at_mut</span>(<span class="number">2</span>);
|
||
<span class="ident">left</span>.<span class="ident">swap_with_slice</span>(<span class="kw-2">&mut</span> <span class="ident">right</span>[<span class="number">1</span>..]);
|
||
}
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">slice</span>, [<span class="number">4</span>, <span class="number">5</span>, <span class="number">3</span>, <span class="number">1</span>, <span class="number">2</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.align_to" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#3425" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[T]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[U]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a></h4></div></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-8" class="section-header"><a href="#safety-8">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-84" class="section-header"><a href="#examples-84">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><div id="method.align_to_mut" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#3485" title="goto source code">[src]</a></div><a href="#method.align_to_mut" class="anchor"></a><h4 class="code-header">pub unsafe fn <a href="#method.align_to_mut" class="fnname">align_to_mut</a><U>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [U]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a></h4></div></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-9" class="section-header"><a href="#safety-9">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-85" class="section-header"><a href="#examples-85">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="kw-2">mut</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_mut</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><div id="method.as_simd" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#3579-3583" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a>>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[T]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[</a><a class="struct" href="https://doc.rust-lang.org/1.59.0/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/1.59.0/core/primitive.slice.html">]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/1.59.0/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/1.59.0/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/1.59.0/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">; LANES]</a>>,<br> <a class="struct" href="https://doc.rust-lang.org/1.59.0/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/1.59.0/core/core_simd/lane_count/trait.SupportedLaneCount.html" title="trait core::core_simd::lane_count::SupportedLaneCount">SupportedLaneCount</a>, </span></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>portable_simd</code>)</div></div></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/1.59.0/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-33" class="section-header"><a href="#panics-33">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-86" class="section-header"><a href="#examples-86">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">horizontal_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><div id="method.as_simd_mut" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#3623-3627" title="goto source code">[src]</a></div><a href="#method.as_simd_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.as_simd_mut" class="fnname">as_simd_mut</a><const LANES: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>>(<br> &mut self<br>) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [</a><a class="struct" href="https://doc.rust-lang.org/1.59.0/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/1.59.0/core/primitive.slice.html">]</a>, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/1.59.0/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/1.59.0/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/1.59.0/core/convert/trait.AsMut.html" title="trait core::convert::AsMut">AsMut</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.array.html">; LANES]</a>>,<br> <a class="struct" href="https://doc.rust-lang.org/1.59.0/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/1.59.0/core/core_simd/lane_count/trait.SupportedLaneCount.html" title="trait core::core_simd::lane_count::SupportedLaneCount">SupportedLaneCount</a>, </span></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>portable_simd</code>)</div></div></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/1.59.0/core/primitive.slice.html#method.align_to_mut" title="slice::align_to_mut"><code>slice::align_to_mut</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>
|
||
<p>This is the mutable version of <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.as_simd" title="slice::as_simd"><code>slice::as_simd</code></a>; see that for examples.</p>
|
||
<h5 id="panics-34" class="section-header"><a href="#panics-34">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>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.is_sorted" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#3662-3664" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a><T>, </span></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>is_sorted</code>)</div></div></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-87" class="section-header"><a href="#examples-87">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><div id="method.is_sorted_by" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#3677-3679" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="enum" href="https://doc.rust-lang.org/1.59.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>>, </span></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>is_sorted</code>)</div></div></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/1.59.0/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><div id="method.is_sorted_by_key" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#3702-3705" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> K,<br> K: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a><K>, </span></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>is_sorted</code>)</div></div></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/1.59.0/core/primitive.slice.html#method.is_sorted"><code>is_sorted</code></a>; see its
|
||
documentation for more information.</p>
|
||
<h5 id="examples-88" class="section-header"><a href="#examples-88">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><div id="method.partition_point" class="method has-srclink"><div 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/1.59.0/src/core/slice/mod.rs.html#3739-3741" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a>, </span></h4></div></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/1.59.0/core/primitive.slice.html#method.binary_search"><code>binary_search</code></a>, <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.binary_search_by"><code>binary_search_by</code></a>, and <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.binary_search_by_key"><code>binary_search_by_key</code></a>.</p>
|
||
<h5 id="examples-89" class="section-header"><a href="#examples-89">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><details class="rustdoc-toggle method-toggle" open><summary><div id="method.take" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#3797" title="goto source code">[src]</a></div><a href="#method.take" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.take" class="fnname">take</a><R>(self: &mut <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&'a [T]</a>, range: R) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&'a [T]</a>> <span class="where fmt-newline">where<br> R: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/range/trait.OneSidedRange.html" title="trait core::ops::range::OneSidedRange">OneSidedRange</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>>, </span></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_take</code>)</div></div></summary><div class="docblock"><p>Removes the subslice corresponding to the given range
|
||
and returns a reference to it.</p>
|
||
<p>Returns <code>None</code> and does not modify the slice if the given
|
||
range is out of bounds.</p>
|
||
<p>Note that this method only accepts one-sided ranges such as
|
||
<code>2..</code> or <code>..6</code>, but not <code>2..6</code>.</p>
|
||
<h5 id="examples-90" class="section-header"><a href="#examples-90">Examples</a></h5>
|
||
<p>Taking the first three elements of a slice:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">slice_take</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">slice</span>: <span class="kw-2">&</span>[<span class="kw">_</span>] <span class="op">=</span> <span class="kw-2">&</span>[<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">first_three</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">take</span>(..<span class="number">3</span>).<span class="ident">unwrap</span>();
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">slice</span>, <span class="kw-2">&</span>[<span class="string">'d'</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">first_three</span>, <span class="kw-2">&</span>[<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>]);</code></pre></div>
|
||
<p>Taking the last two elements of a slice:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">slice_take</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">slice</span>: <span class="kw-2">&</span>[<span class="kw">_</span>] <span class="op">=</span> <span class="kw-2">&</span>[<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">tail</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">take</span>(<span class="number">2</span>..).<span class="ident">unwrap</span>();
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">slice</span>, <span class="kw-2">&</span>[<span class="string">'a'</span>, <span class="string">'b'</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">tail</span>, <span class="kw-2">&</span>[<span class="string">'c'</span>, <span class="string">'d'</span>]);</code></pre></div>
|
||
<p>Getting <code>None</code> when <code>range</code> is out of bounds:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">slice_take</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">slice</span>: <span class="kw-2">&</span>[<span class="kw">_</span>] <span class="op">=</span> <span class="kw-2">&</span>[<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>];
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">slice</span>.<span class="ident">take</span>(<span class="number">5</span>..));
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">slice</span>.<span class="ident">take</span>(..<span class="number">5</span>));
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">slice</span>.<span class="ident">take</span>(..<span class="op">=</span><span class="number">4</span>));
|
||
<span class="kw">let</span> <span class="ident">expected</span>: <span class="kw-2">&</span>[<span class="ident">char</span>] <span class="op">=</span> <span class="kw-2">&</span>[<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>];
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="ident">expected</span>), <span class="ident">slice</span>.<span class="ident">take</span>(..<span class="number">4</span>));</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.take_mut" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#3866-3869" title="goto source code">[src]</a></div><a href="#method.take_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.take_mut" class="fnname">take_mut</a><R>(self: &mut <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&'a mut [T]</a>, range: R) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&'a mut [T]</a>> <span class="where fmt-newline">where<br> R: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/range/trait.OneSidedRange.html" title="trait core::ops::range::OneSidedRange">OneSidedRange</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>>, </span></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_take</code>)</div></div></summary><div class="docblock"><p>Removes the subslice corresponding to the given range
|
||
and returns a mutable reference to it.</p>
|
||
<p>Returns <code>None</code> and does not modify the slice if the given
|
||
range is out of bounds.</p>
|
||
<p>Note that this method only accepts one-sided ranges such as
|
||
<code>2..</code> or <code>..6</code>, but not <code>2..6</code>.</p>
|
||
<h5 id="examples-91" class="section-header"><a href="#examples-91">Examples</a></h5>
|
||
<p>Taking the first three elements of a slice:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">slice_take</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">slice</span>: <span class="kw-2">&mut</span> [<span class="kw">_</span>] <span class="op">=</span> <span class="kw-2">&mut</span> [<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">first_three</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">take_mut</span>(..<span class="number">3</span>).<span class="ident">unwrap</span>();
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">slice</span>, <span class="kw-2">&mut</span> [<span class="string">'d'</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">first_three</span>, <span class="kw-2">&mut</span> [<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>]);</code></pre></div>
|
||
<p>Taking the last two elements of a slice:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">slice_take</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">slice</span>: <span class="kw-2">&mut</span> [<span class="kw">_</span>] <span class="op">=</span> <span class="kw-2">&mut</span> [<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">tail</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">take_mut</span>(<span class="number">2</span>..).<span class="ident">unwrap</span>();
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">slice</span>, <span class="kw-2">&mut</span> [<span class="string">'a'</span>, <span class="string">'b'</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">tail</span>, <span class="kw-2">&mut</span> [<span class="string">'c'</span>, <span class="string">'d'</span>]);</code></pre></div>
|
||
<p>Getting <code>None</code> when <code>range</code> is out of bounds:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#![<span class="ident">feature</span>(<span class="ident">slice_take</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">slice</span>: <span class="kw-2">&mut</span> [<span class="kw">_</span>] <span class="op">=</span> <span class="kw-2">&mut</span> [<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>];
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">slice</span>.<span class="ident">take_mut</span>(<span class="number">5</span>..));
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">slice</span>.<span class="ident">take_mut</span>(..<span class="number">5</span>));
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, <span class="ident">slice</span>.<span class="ident">take_mut</span>(..<span class="op">=</span><span class="number">4</span>));
|
||
<span class="kw">let</span> <span class="ident">expected</span>: <span class="kw-2">&mut</span> [<span class="kw">_</span>] <span class="op">=</span> <span class="kw-2">&mut</span> [<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>];
|
||
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="ident">expected</span>), <span class="ident">slice</span>.<span class="ident">take_mut</span>(..<span class="number">4</span>));</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.take_first" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#3905" title="goto source code">[src]</a></div><a href="#method.take_first" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.take_first" class="fnname">take_first</a>(self: &mut <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&'a [T]</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&'a </a>T></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_take</code>)</div></div></summary><div class="docblock"><p>Removes the first element of the slice and returns a reference
|
||
to it.</p>
|
||
<p>Returns <code>None</code> if the slice is empty.</p>
|
||
<h5 id="examples-92" class="section-header"><a href="#examples-92">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_take</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">slice</span>: <span class="kw-2">&</span>[<span class="kw">_</span>] <span class="op">=</span> <span class="kw-2">&</span>[<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>];
|
||
<span class="kw">let</span> <span class="ident">first</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">take_first</span>().<span class="ident">unwrap</span>();
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">slice</span>, <span class="kw-2">&</span>[<span class="string">'b'</span>, <span class="string">'c'</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">first</span>, <span class="kw-2">&</span><span class="string">'a'</span>);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.take_first_mut" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#3930" title="goto source code">[src]</a></div><a href="#method.take_first_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.take_first_mut" class="fnname">take_first_mut</a>(self: &mut <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&'a mut [T]</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&'a mut </a>T></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_take</code>)</div></div></summary><div class="docblock"><p>Removes the first element of the slice and returns a mutable
|
||
reference to it.</p>
|
||
<p>Returns <code>None</code> if the slice is empty.</p>
|
||
<h5 id="examples-93" class="section-header"><a href="#examples-93">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_take</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">slice</span>: <span class="kw-2">&mut</span> [<span class="kw">_</span>] <span class="op">=</span> <span class="kw-2">&mut</span> [<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>];
|
||
<span class="kw">let</span> <span class="ident">first</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">take_first_mut</span>().<span class="ident">unwrap</span>();
|
||
<span class="kw-2">*</span><span class="ident">first</span> <span class="op">=</span> <span class="string">'d'</span>;
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">slice</span>, <span class="kw-2">&</span>[<span class="string">'b'</span>, <span class="string">'c'</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">first</span>, <span class="kw-2">&</span><span class="string">'d'</span>);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.take_last" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#3954" title="goto source code">[src]</a></div><a href="#method.take_last" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.take_last" class="fnname">take_last</a>(self: &mut <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&'a [T]</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&'a </a>T></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_take</code>)</div></div></summary><div class="docblock"><p>Removes the last element of the slice and returns a reference
|
||
to it.</p>
|
||
<p>Returns <code>None</code> if the slice is empty.</p>
|
||
<h5 id="examples-94" class="section-header"><a href="#examples-94">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_take</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">slice</span>: <span class="kw-2">&</span>[<span class="kw">_</span>] <span class="op">=</span> <span class="kw-2">&</span>[<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>];
|
||
<span class="kw">let</span> <span class="ident">last</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">take_last</span>().<span class="ident">unwrap</span>();
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">slice</span>, <span class="kw-2">&</span>[<span class="string">'a'</span>, <span class="string">'b'</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">last</span>, <span class="kw-2">&</span><span class="string">'c'</span>);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.take_last_mut" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/mod.rs.html#3979" title="goto source code">[src]</a></div><a href="#method.take_last_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.take_last_mut" class="fnname">take_last_mut</a>(self: &mut <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&'a mut [T]</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&'a mut </a>T></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>slice_take</code>)</div></div></summary><div class="docblock"><p>Removes the last element of the slice and returns a mutable
|
||
reference to it.</p>
|
||
<p>Returns <code>None</code> if the slice is empty.</p>
|
||
<h5 id="examples-95" class="section-header"><a href="#examples-95">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_take</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">slice</span>: <span class="kw-2">&mut</span> [<span class="kw">_</span>] <span class="op">=</span> <span class="kw-2">&mut</span> [<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>];
|
||
<span class="kw">let</span> <span class="ident">last</span> <span class="op">=</span> <span class="ident">slice</span>.<span class="ident">take_last_mut</span>().<span class="ident">unwrap</span>();
|
||
<span class="kw-2">*</span><span class="ident">last</span> <span class="op">=</span> <span class="string">'d'</span>;
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">slice</span>, <span class="kw-2">&</span>[<span class="string">'a'</span>, <span class="string">'b'</span>]);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">last</span>, <span class="kw-2">&</span><span class="string">'d'</span>);</code></pre></div>
|
||
</div></details></div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.is_ascii" class="method has-srclink"><div 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/1.59.0/src/core/slice/ascii.rs.html#16" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.bool.html">bool</a></h4></div></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><div id="method.eq_ignore_ascii_case" class="method has-srclink"><div 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/1.59.0/src/core/slice/ascii.rs.html#27" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.slice.html">&[</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a></h4></div></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><div id="method.make_ascii_uppercase" class="method has-srclink"><div 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/1.59.0/src/core/slice/ascii.rs.html#42" title="goto source code">[src]</a></div><a href="#method.make_ascii_uppercase" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.make_ascii_uppercase" class="fnname">make_ascii_uppercase</a>(&mut self)</h4></div></summary><div class="docblock"><p>Converts this slice to its ASCII upper case equivalent in-place.</p>
|
||
<p>ASCII letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’,
|
||
but non-ASCII letters are unchanged.</p>
|
||
<p>To return a new uppercased value without modifying the existing one, use
|
||
<a href="#method.to_ascii_uppercase"><code>to_ascii_uppercase</code></a>.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.make_ascii_lowercase" class="method has-srclink"><div 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/1.59.0/src/core/slice/ascii.rs.html#59" title="goto source code">[src]</a></div><a href="#method.make_ascii_lowercase" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.make_ascii_lowercase" class="fnname">make_ascii_lowercase</a>(&mut self)</h4></div></summary><div class="docblock"><p>Converts this slice to its ASCII lower case equivalent in-place.</p>
|
||
<p>ASCII letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’,
|
||
but non-ASCII letters are unchanged.</p>
|
||
<p>To return a new lowercased value without modifying the existing one, use
|
||
<a href="#method.to_ascii_lowercase"><code>to_ascii_lowercase</code></a>.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.escape_ascii" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/slice/ascii.rs.html#80" title="goto source code">[src]</a></div><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/1.59.0/core/slice/ascii/struct.EscapeAscii.html" title="struct core::slice::ascii::EscapeAscii">EscapeAscii</a><'_></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>inherent_ascii_escape</code>)</div></div></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-96" class="section-header"><a href="#examples-96">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">inherent_ascii_escape</span>)]</span>
|
||
|
||
<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></div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.sort" class="method has-srclink"><div 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/1.59.0/src/alloc/slice.rs.html#272-274" title="goto source code">[src]</a></div><a href="#method.sort" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.sort" class="fnname">sort</a>(&mut self) <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>, </span></h4></div></summary><div class="docblock"><p>Sorts the slice.</p>
|
||
<p>This sort is stable (i.e., does not reorder equal elements) and <em>O</em>(<em>n</em> * log(<em>n</em>)) worst-case.</p>
|
||
<p>When applicable, unstable sorting is preferred because it is generally faster than stable
|
||
sorting and it doesn’t allocate auxiliary memory.
|
||
See <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.sort_unstable"><code>sort_unstable</code></a>.</p>
|
||
<h5 id="current-implementation-6" class="section-header"><a href="#current-implementation-6">Current implementation</a></h5>
|
||
<p>The current algorithm is an adaptive, iterative merge sort inspired by
|
||
<a href="https://en.wikipedia.org/wiki/Timsort">timsort</a>.
|
||
It is designed to be very fast in cases where the slice is nearly sorted, or consists of
|
||
two or more sorted sequences concatenated one after another.</p>
|
||
<p>Also, it allocates temporary storage half the size of <code>self</code>, but for short slices a
|
||
non-allocating insertion sort is used instead.</p>
|
||
<h5 id="examples-97" class="section-header"><a href="#examples-97">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="op">-</span><span class="number">5</span>, <span class="number">4</span>, <span class="number">1</span>, <span class="op">-</span><span class="number">3</span>, <span class="number">2</span>];
|
||
|
||
<span class="ident">v</span>.<span class="ident">sort</span>();
|
||
<span class="macro">assert!</span>(<span class="ident">v</span> <span class="op">==</span> [<span class="op">-</span><span class="number">5</span>, <span class="op">-</span><span class="number">3</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">4</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.sort_by" class="method has-srclink"><div 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/1.59.0/src/alloc/slice.rs.html#327-329" title="goto source code">[src]</a></div><a href="#method.sort_by" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.sort_by" class="fnname">sort_by</a><F>(&mut self, compare: F) <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T, <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>, </span></h4></div></summary><div class="docblock"><p>Sorts the slice with a comparator function.</p>
|
||
<p>This sort is stable (i.e., does not reorder equal elements) and <em>O</em>(<em>n</em> * log(<em>n</em>)) worst-case.</p>
|
||
<p>The comparator function must define a total ordering for the elements in the slice. If
|
||
the ordering is not total, the order of the elements is unspecified. An order is a
|
||
total order if it is (for all <code>a</code>, <code>b</code> and <code>c</code>):</p>
|
||
<ul>
|
||
<li>total and antisymmetric: exactly one of <code>a < b</code>, <code>a == b</code> or <code>a > b</code> is true, and</li>
|
||
<li>transitive, <code>a < b</code> and <code>b < c</code> implies <code>a < c</code>. The same must hold for both <code>==</code> and <code>></code>.</li>
|
||
</ul>
|
||
<p>For example, while <a href="https://doc.rust-lang.org/1.59.0/core/primitive.f64.html" title="f64"><code>f64</code></a> doesn’t implement <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html" title="Ord"><code>Ord</code></a> because <code>NaN != NaN</code>, we can use
|
||
<code>partial_cmp</code> as our sort function when we know the slice doesn’t contain a <code>NaN</code>.</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">floats</span> <span class="op">=</span> [<span class="number">5f64</span>, <span class="number">4.0</span>, <span class="number">1.0</span>, <span class="number">3.0</span>, <span class="number">2.0</span>];
|
||
<span class="ident">floats</span>.<span class="ident">sort_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="ident">partial_cmp</span>(<span class="ident">b</span>).<span class="ident">unwrap</span>());
|
||
<span class="macro">assert_eq!</span>(<span class="ident">floats</span>, [<span class="number">1.0</span>, <span class="number">2.0</span>, <span class="number">3.0</span>, <span class="number">4.0</span>, <span class="number">5.0</span>]);</code></pre></div>
|
||
<p>When applicable, unstable sorting is preferred because it is generally faster than stable
|
||
sorting and it doesn’t allocate auxiliary memory.
|
||
See <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.sort_unstable_by"><code>sort_unstable_by</code></a>.</p>
|
||
<h5 id="current-implementation-7" class="section-header"><a href="#current-implementation-7">Current implementation</a></h5>
|
||
<p>The current algorithm is an adaptive, iterative merge sort inspired by
|
||
<a href="https://en.wikipedia.org/wiki/Timsort">timsort</a>.
|
||
It is designed to be very fast in cases where the slice is nearly sorted, or consists of
|
||
two or more sorted sequences concatenated one after another.</p>
|
||
<p>Also, it allocates temporary storage half the size of <code>self</code>, but for short slices a
|
||
non-allocating insertion sort is used instead.</p>
|
||
<h5 id="examples-98" class="section-header"><a href="#examples-98">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="number">5</span>, <span class="number">4</span>, <span class="number">1</span>, <span class="number">3</span>, <span class="number">2</span>];
|
||
<span class="ident">v</span>.<span class="ident">sort_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="ident">cmp</span>(<span class="ident">b</span>));
|
||
<span class="macro">assert!</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="comment">// reverse sorting</span>
|
||
<span class="ident">v</span>.<span class="ident">sort_by</span>(<span class="op">|</span><span class="ident">a</span>, <span class="ident">b</span><span class="op">|</span> <span class="ident">b</span>.<span class="ident">cmp</span>(<span class="ident">a</span>));
|
||
<span class="macro">assert!</span>(<span class="ident">v</span> <span class="op">==</span> [<span class="number">5</span>, <span class="number">4</span>, <span class="number">3</span>, <span class="number">2</span>, <span class="number">1</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.sort_by_key" class="method has-srclink"><div 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/1.59.0/src/alloc/slice.rs.html#368-371" title="goto source code">[src]</a></div><a href="#method.sort_by_key" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.sort_by_key" class="fnname">sort_by_key</a><K, F>(&mut self, f: F) <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> K,<br> K: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>, </span></h4></div></summary><div class="docblock"><p>Sorts the slice with a key extraction function.</p>
|
||
<p>This sort is stable (i.e., does not reorder equal elements) and <em>O</em>(<em>m</em> * <em>n</em> * log(<em>n</em>))
|
||
worst-case, where the key function is <em>O</em>(<em>m</em>).</p>
|
||
<p>For expensive key functions (e.g. functions that are not simple property accesses or
|
||
basic operations), <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.sort_by_cached_key"><code>sort_by_cached_key</code></a> is likely to be
|
||
significantly faster, as it does not recompute element keys.</p>
|
||
<p>When applicable, unstable sorting is preferred because it is generally faster than stable
|
||
sorting and it doesn’t allocate auxiliary memory.
|
||
See <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.sort_unstable_by_key"><code>sort_unstable_by_key</code></a>.</p>
|
||
<h5 id="current-implementation-8" class="section-header"><a href="#current-implementation-8">Current implementation</a></h5>
|
||
<p>The current algorithm is an adaptive, iterative merge sort inspired by
|
||
<a href="https://en.wikipedia.org/wiki/Timsort">timsort</a>.
|
||
It is designed to be very fast in cases where the slice is nearly sorted, or consists of
|
||
two or more sorted sequences concatenated one after another.</p>
|
||
<p>Also, it allocates temporary storage half the size of <code>self</code>, but for short slices a
|
||
non-allocating insertion sort is used instead.</p>
|
||
<h5 id="examples-99" class="section-header"><a href="#examples-99">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="op">-</span><span class="number">5i32</span>, <span class="number">4</span>, <span class="number">1</span>, <span class="op">-</span><span class="number">3</span>, <span class="number">2</span>];
|
||
|
||
<span class="ident">v</span>.<span class="ident">sort_by_key</span>(<span class="op">|</span><span class="ident">k</span><span class="op">|</span> <span class="ident">k</span>.<span class="ident">abs</span>());
|
||
<span class="macro">assert!</span>(<span class="ident">v</span> <span class="op">==</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="op">-</span><span class="number">3</span>, <span class="number">4</span>, <span class="op">-</span><span class="number">5</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.sort_by_cached_key" class="method has-srclink"><div class="rightside"><span class="since" title="Stable since Rust version 1.34.0">1.34.0</span><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/alloc/slice.rs.html#411-414" title="goto source code">[src]</a></div><a href="#method.sort_by_cached_key" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.sort_by_cached_key" class="fnname">sort_by_cached_key</a><K, F>(&mut self, f: F) <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T) -> K,<br> K: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>, </span></h4></div></summary><div class="docblock"><p>Sorts the slice with a key extraction function.</p>
|
||
<p>During sorting, the key function is called only once per element.</p>
|
||
<p>This sort is stable (i.e., does not reorder equal elements) and <em>O</em>(<em>m</em> * <em>n</em> + <em>n</em> * log(<em>n</em>))
|
||
worst-case, where the key function is <em>O</em>(<em>m</em>).</p>
|
||
<p>For simple key functions (e.g., functions that are property accesses or
|
||
basic operations), <a href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html#method.sort_by_key"><code>sort_by_key</code></a> is likely to be
|
||
faster.</p>
|
||
<h5 id="current-implementation-9" class="section-header"><a href="#current-implementation-9">Current implementation</a></h5>
|
||
<p>The current algorithm is based on <a href="https://github.com/orlp/pdqsort">pattern-defeating quicksort</a> by Orson Peters,
|
||
which combines the fast average case of randomized quicksort with the fast worst case of
|
||
heapsort, while achieving linear time on slices with certain patterns. It uses some
|
||
randomization to avoid degenerate cases, but with a fixed seed to always provide
|
||
deterministic behavior.</p>
|
||
<p>In the worst case, the algorithm allocates temporary storage in a <code>Vec<(K, usize)></code> the
|
||
length of the slice.</p>
|
||
<h5 id="examples-100" class="section-header"><a href="#examples-100">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="op">-</span><span class="number">5i32</span>, <span class="number">4</span>, <span class="number">32</span>, <span class="op">-</span><span class="number">3</span>, <span class="number">2</span>];
|
||
|
||
<span class="ident">v</span>.<span class="ident">sort_by_cached_key</span>(<span class="op">|</span><span class="ident">k</span><span class="op">|</span> <span class="ident">k</span>.<span class="ident">to_string</span>());
|
||
<span class="macro">assert!</span>(<span class="ident">v</span> <span class="op">==</span> [<span class="op">-</span><span class="number">3</span>, <span class="op">-</span><span class="number">5</span>, <span class="number">2</span>, <span class="number">32</span>, <span class="number">4</span>]);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.to_vec" class="method has-srclink"><div 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/1.59.0/src/alloc/slice.rs.html#470-472" title="goto source code">[src]</a></div><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/1.59.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><T, <a class="struct" href="https://doc.rust-lang.org/1.59.0/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/1.59.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, </span></h4></div></summary><div class="docblock"><p>Copies <code>self</code> into a new <code>Vec</code>.</p>
|
||
<h5 id="examples-101" class="section-header"><a href="#examples-101">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><div id="method.to_vec_in" class="method has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/alloc/slice.rs.html#493-495" title="goto source code">[src]</a></div><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/1.59.0/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/1.59.0/core/alloc/trait.Allocator.html" title="trait core::alloc::Allocator">Allocator</a>,<br> T: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, </span></h4></div><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>allocator_api</code>)</div></div></summary><div class="docblock"><p>Copies <code>self</code> into a new <code>Vec</code> with an allocator.</p>
|
||
<h5 id="examples-102" class="section-header"><a href="#examples-102">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><div id="method.repeat" class="method has-srclink"><div 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/1.59.0/src/alloc/slice.rs.html#544-546" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.usize.html">usize</a>) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><T, <a class="struct" href="https://doc.rust-lang.org/1.59.0/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/1.59.0/core/marker/trait.Copy.html" title="trait core::marker::Copy">Copy</a>, </span></h4></div></summary><div class="docblock"><p>Creates a vector by repeating a slice <code>n</code> times.</p>
|
||
<h5 id="panics-35" class="section-header"><a href="#panics-35">Panics</a></h5>
|
||
<p>This function will panic if the capacity would overflow.</p>
|
||
<h5 id="examples-103" class="section-header"><a href="#examples-103">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><div id="method.concat" class="method has-srclink"><div 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/1.59.0/src/alloc/slice.rs.html#611-613" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a> as <a class="trait" href="https://doc.rust-lang.org/1.59.0/alloc/slice/trait.Concat.html" title="trait alloc::slice::Concat">Concat</a><Item>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.59.0/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/1.59.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,<br> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>: <a class="trait" href="https://doc.rust-lang.org/1.59.0/alloc/slice/trait.Concat.html" title="trait alloc::slice::Concat">Concat</a><Item>, </span></h4></div></summary><div class="docblock"><p>Flattens a slice of <code>T</code> into a single value <code>Self::Output</code>.</p>
|
||
<h5 id="examples-104" class="section-header"><a href="#examples-104">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><div id="method.join" class="method has-srclink"><div 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/1.59.0/src/alloc/slice.rs.html#629-631" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a> as <a class="trait" href="https://doc.rust-lang.org/1.59.0/alloc/slice/trait.Join.html" title="trait alloc::slice::Join">Join</a><Separator>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.59.0/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/1.59.0/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>: <a class="trait" href="https://doc.rust-lang.org/1.59.0/alloc/slice/trait.Join.html" title="trait alloc::slice::Join">Join</a><Separator>, </span></h4></div></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-105" class="section-header"><a href="#examples-105">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><div id="method.connect" class="method has-srclink"><div 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/1.59.0/src/alloc/slice.rs.html#648-650" title="goto source code">[src]</a></div><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/1.59.0/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a> as <a class="trait" href="https://doc.rust-lang.org/1.59.0/alloc/slice/trait.Join.html" title="trait alloc::slice::Join">Join</a><Separator>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.59.0/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/1.59.0/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>: <a class="trait" href="https://doc.rust-lang.org/1.59.0/alloc/slice/trait.Join.html" title="trait alloc::slice::Join">Join</a><Separator>, </span></h4></div><div class="item-info"><div class="stab deprecated"><span class="emoji">👎</span> Deprecated since 1.3.0: <p>renamed to join</p>
|
||
</div></div></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-106" class="section-header"><a href="#examples-106">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 class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.to_ascii_uppercase" class="method has-srclink"><div 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/1.59.0/src/alloc/slice.rs.html#673" title="goto source code">[src]</a></div><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/1.59.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.u8.html">u8</a>, <a class="struct" href="https://doc.rust-lang.org/1.59.0/alloc/alloc/struct.Global.html" title="struct alloc::alloc::Global">Global</a>></h4></div></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/1.59.0/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><div id="method.to_ascii_lowercase" class="method has-srclink"><div 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/1.59.0/src/alloc/slice.rs.html#693" title="goto source code">[src]</a></div><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/1.59.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.u8.html">u8</a>, <a class="struct" href="https://doc.rust-lang.org/1.59.0/alloc/alloc/struct.Global.html" title="struct alloc::alloc::Global">Global</a>></h4></div></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/1.59.0/core/primitive.slice.html#method.make_ascii_lowercase"><code>make_ascii_lowercase</code></a>.</p>
|
||
</div></details></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><div id="impl-AsMut%3C%5B%3CA%20as%20Array%3E%3A%3AItem%5D%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1543-1548" title="goto source code">[src]</a></div><a href="#impl-AsMut%3C%5B%3CA%20as%20Array%3E%3A%3AItem%5D%3E" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.AsMut.html" title="trait core::convert::AsMut">AsMut</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">[</a><A as <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>>::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.as_mut" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1545-1547" title="goto source code">[src]</a></div><a href="#method.as_mut" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/convert/trait.AsMut.html#tymethod.as_mut" class="fnname">as_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [</a>A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a></h4></div></summary><div class='docblock'><p>Performs the conversion.</p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-AsRef%3C%5B%3CA%20as%20Array%3E%3A%3AItem%5D%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1536-1541" title="goto source code">[src]</a></div><a href="#impl-AsRef%3C%5B%3CA%20as%20Array%3E%3A%3AItem%5D%3E" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">[</a><A as <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>>::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.as_ref" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1538-1540" title="goto source code">[src]</a></div><a href="#method.as_ref" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/convert/trait.AsRef.html#tymethod.as_ref" class="fnname">as_ref</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[</a>A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a></h4></div></summary><div class='docblock'><p>Performs the conversion.</p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-Borrow%3C%5B%3CA%20as%20Array%3E%3A%3AItem%5D%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1550-1555" title="goto source code">[src]</a></div><a href="#impl-Borrow%3C%5B%3CA%20as%20Array%3E%3A%3AItem%5D%3E" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">[</a><A as <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>>::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.borrow" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1552-1554" title="goto source code">[src]</a></div><a href="#method.borrow" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/borrow/trait.Borrow.html#tymethod.borrow" class="fnname">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[</a>A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a></h4></div></summary><div class='docblock'><p>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.59.0/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-BorrowMut%3C%5B%3CA%20as%20Array%3E%3A%3AItem%5D%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1557-1562" title="goto source code">[src]</a></div><a href="#impl-BorrowMut%3C%5B%3CA%20as%20Array%3E%3A%3AItem%5D%3E" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">[</a><A as <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>>::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.borrow_mut" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1559-1561" title="goto source code">[src]</a></div><a href="#method.borrow_mut" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fnname">borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [</a>A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a></h4></div></summary><div class='docblock'><p>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.59.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-Clone" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1801-1824" title="goto source code">[src]</a></div><a href="#impl-Clone" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A> <span class="where fmt-newline">where<br> A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, </span></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.clone" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1806-1808" title="goto source code">[src]</a></div><a href="#method.clone" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/clone/trait.Clone.html#tymethod.clone" class="fnname">clone</a>(&self) -> <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h4></div></summary><div class='docblock'><p>Returns a copy of the value. <a href="https://doc.rust-lang.org/1.59.0/core/clone/trait.Clone.html#tymethod.clone">Read more</a></p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.clone_from" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1810-1823" title="goto source code">[src]</a></div><a href="#method.clone_from" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/clone/trait.Clone.html#method.clone_from" class="fnname">clone_from</a>(&mut self, source: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>Self)</h4></div></summary><div class='docblock'><p>Performs copy-assignment from <code>source</code>. <a href="https://doc.rust-lang.org/1.59.0/core/clone/trait.Clone.html#method.clone_from">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-Debug" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1757-1764" title="goto source code">[src]</a></div><a href="#impl-Debug" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A> <span class="where fmt-newline">where<br> A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a>, </span></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.fmt" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1761-1763" title="goto source code">[src]</a></div><a href="#method.fmt" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/fmt/trait.Debug.html#tymethod.fmt" class="fnname">fmt</a>(&self, f: &mut <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a><'_>) -> <a class="type" href="https://doc.rust-lang.org/1.59.0/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></h4></div></summary><div class='docblock'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/1.59.0/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-Default" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1766-1771" title="goto source code">[src]</a></div><a href="#impl-Default" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/default/trait.Default.html" title="trait core::default::Default">Default</a> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.default" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1768-1770" title="goto source code">[src]</a></div><a href="#method.default" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/default/trait.Default.html#tymethod.default" class="fnname">default</a>() -> <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h4></div></summary><div class='docblock'><p>Returns the “default value” for a type. <a href="https://doc.rust-lang.org/1.59.0/core/default/trait.Default.html#tymethod.default">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-Deref" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1515-1524" title="goto source code">[src]</a></div><a href="#impl-Deref" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><div 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/1.59.0/core/ops/deref/trait.Deref.html#associatedtype.Target" class="associatedtype">Target</a> = <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">[</a>A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a></h4></div></summary><div class='docblock'><p>The resulting type after dereferencing.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.deref" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1518-1523" title="goto source code">[src]</a></div><a href="#method.deref" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/ops/deref/trait.Deref.html#tymethod.deref" class="fnname">deref</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[</a>A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a></h4></div></summary><div class='docblock'><p>Dereferences the value.</p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-DerefMut" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1526-1534" title="goto source code">[src]</a></div><a href="#impl-DerefMut" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/deref/trait.DerefMut.html" title="trait core::ops::deref::DerefMut">DerefMut</a> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.deref_mut" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1528-1533" title="goto source code">[src]</a></div><a href="#method.deref_mut" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/ops/deref/trait.DerefMut.html#tymethod.deref_mut" class="fnname">deref_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&mut [</a>A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a></h4></div></summary><div class='docblock'><p>Mutably dereferences the value.</p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-Drop" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1788-1799" title="goto source code">[src]</a></div><a href="#impl-Drop" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/drop/trait.Drop.html" title="trait core::ops::drop::Drop">Drop</a> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.drop" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1789-1798" title="goto source code">[src]</a></div><a href="#method.drop" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/ops/drop/trait.Drop.html#tymethod.drop" class="fnname">drop</a>(&mut self)</h4></div></summary><div class='docblock'><p>Executes the destructor for this type. <a href="https://doc.rust-lang.org/1.59.0/core/ops/drop/trait.Drop.html#tymethod.drop">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-Extend%3C%3CA%20as%20Array%3E%3A%3AItem%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1732-1755" title="goto source code">[src]</a></div><a href="#impl-Extend%3C%3CA%20as%20Array%3E%3A%3AItem%3E" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><<A as <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>>::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.extend" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1733-1754" title="goto source code">[src]</a></div><a href="#method.extend" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.Extend.html#tymethod.extend" class="fnname">extend</a><I: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a><Item = A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>>>(&mut self, iterable: I)</h4></div></summary><div class='docblock'><p>Extends a collection with the contents of an iterator. <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.Extend.html#tymethod.extend">Read more</a></p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.extend_one" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/iter/traits/collect.rs.html#343" title="goto source code">[src]</a></div><a href="#method.extend_one" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.Extend.html#method.extend_one" class="fnname">extend_one</a>(&mut self, item: A)</h4></div></summary><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>extend_one</code>)</div></div><div class='docblock'><p>Extends a collection with exactly one element.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.extend_reserve" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/iter/traits/collect.rs.html#351" title="goto source code">[src]</a></div><a href="#method.extend_reserve" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.Extend.html#method.extend_reserve" class="fnname">extend_reserve</a>(&mut self, additional: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.usize.html">usize</a>)</h4></div></summary><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>extend_one</code>)</div></div><div class='docblock'><p>Reserves capacity in a collection for the given number of additional elements. <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.Extend.html#method.extend_reserve">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-From%3C%26%27a%20%5B%3CA%20as%20Array%3E%3A%3AItem%5D%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1668-1683" title="goto source code">[src]</a></div><a href="#impl-From%3C%26%27a%20%5B%3CA%20as%20Array%3E%3A%3AItem%5D%3E" class="anchor"></a><h3 class="code-header in-band">impl<'a, A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&'a [</a><A as <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>>::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A> <span class="where fmt-newline">where<br> A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, </span></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.from" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1674-1676" title="goto source code">[src]</a></div><a href="#method.from" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(slice: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&'a [</a>A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>) -> <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h4></div></summary><div class='docblock'><p>Performs the conversion.</p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-From%3CA%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1692-1697" title="goto source code">[src]</a></div><a href="#impl-From%3CA%3E" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><A> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.from-2" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1694-1696" title="goto source code">[src]</a></div><a href="#method.from-2" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(array: A) -> <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h4></div></summary><div class='docblock'><p>Performs the conversion.</p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-From%3CVec%3C%3CA%20as%20Array%3E%3A%3AItem%2C%20Global%3E%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1685-1690" title="goto source code">[src]</a></div><a href="#impl-From%3CVec%3C%3CA%20as%20Array%3E%3A%3AItem%2C%20Global%3E%3E" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><<a class="struct" href="https://doc.rust-lang.org/1.59.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<A as <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>>::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>, <a class="struct" href="https://doc.rust-lang.org/1.59.0/alloc/alloc/struct.Global.html" title="struct alloc::alloc::Global">Global</a>>> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.from-1" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1687-1689" title="goto source code">[src]</a></div><a href="#method.from-1" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(vec: <a class="struct" href="https://doc.rust-lang.org/1.59.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>>) -> <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h4></div></summary><div class='docblock'><p>Performs the conversion.</p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-FromIterator%3C%3CA%20as%20Array%3E%3A%3AItem%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1723-1730" title="goto source code">[src]</a></div><a href="#impl-FromIterator%3C%3CA%20as%20Array%3E%3A%3AItem%3E" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.FromIterator.html" title="trait core::iter::traits::collect::FromIterator">FromIterator</a><<A as <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>>::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.from_iter" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1725-1729" title="goto source code">[src]</a></div><a href="#method.from_iter" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.FromIterator.html#tymethod.from_iter" class="fnname">from_iter</a><I: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a><Item = A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>>>(iterable: I) -> <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h4></div></summary><div class='docblock'><p>Creates a value from an iterator. <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.FromIterator.html#tymethod.from_iter">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-Hash" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1858-1865" title="goto source code">[src]</a></div><a href="#impl-Hash" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A> <span class="where fmt-newline">where<br> A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a>, </span></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.hash" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1862-1864" title="goto source code">[src]</a></div><a href="#method.hash" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/hash/trait.Hash.html#tymethod.hash" class="fnname">hash</a><H: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/hash/trait.Hasher.html" title="trait core::hash::Hasher">Hasher</a>>(&self, state: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&mut </a>H)</h4></div></summary><div class='docblock'><p>Feeds this value into the given <a href="https://doc.rust-lang.org/1.59.0/core/hash/trait.Hasher.html" title="Hasher"><code>Hasher</code></a>. <a href="https://doc.rust-lang.org/1.59.0/core/hash/trait.Hash.html#tymethod.hash">Read more</a></p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.hash_slice" class="method trait-impl has-srclink"><div 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/1.59.0/src/core/hash/mod.rs.html#237-239" title="goto source code">[src]</a></div><a href="#method.hash_slice" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/hash/trait.Hash.html#method.hash_slice" class="fnname">hash_slice</a><H>(data: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">&[Self]</a>, state: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&mut </a>H) <span class="where fmt-newline">where<br> H: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/hash/trait.Hasher.html" title="trait core::hash::Hasher">Hasher</a>, </span></h4></div></summary><div class='docblock'><p>Feeds a slice of this type into the given <a href="https://doc.rust-lang.org/1.59.0/core/hash/trait.Hasher.html" title="Hasher"><code>Hasher</code></a>. <a href="https://doc.rust-lang.org/1.59.0/core/hash/trait.Hash.html#method.hash_slice">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-Index%3CI%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1699-1705" title="goto source code">[src]</a></div><a href="#impl-Index%3CI%3E" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>, I: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/slice/index/trait.SliceIndex.html" title="trait core::slice::index::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">[</a>A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/index/trait.Index.html" title="trait core::ops::index::Index">Index</a><I> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><div id="associatedtype.Output" class="type trait-impl has-srclink"><a href="#associatedtype.Output" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.59.0/core/ops/index/trait.Index.html#associatedtype.Output" class="associatedtype">Output</a> = I::<a class="associatedtype" href="https://doc.rust-lang.org/1.59.0/core/slice/index/trait.SliceIndex.html#associatedtype.Output" title="type core::slice::index::SliceIndex::Output">Output</a></h4></div></summary><div class='docblock'><p>The returned type after indexing.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.index" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1702-1704" title="goto source code">[src]</a></div><a href="#method.index" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/ops/index/trait.Index.html#tymethod.index" class="fnname">index</a>(&self, index: I) -> &I::<a class="associatedtype" href="https://doc.rust-lang.org/1.59.0/core/slice/index/trait.SliceIndex.html#associatedtype.Output" title="type core::slice::index::SliceIndex::Output">Output</a></h4></div></summary><div class='docblock'><p>Performs the indexing (<code>container[index]</code>) operation. <a href="https://doc.rust-lang.org/1.59.0/core/ops/index/trait.Index.html#tymethod.index">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-IndexMut%3CI%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1707-1711" title="goto source code">[src]</a></div><a href="#impl-IndexMut%3CI%3E" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>, I: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/slice/index/trait.SliceIndex.html" title="trait core::slice::index::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">[</a>A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a><a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.slice.html">]</a>>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/index/trait.IndexMut.html" title="trait core::ops::index::IndexMut">IndexMut</a><I> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.index_mut" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1708-1710" title="goto source code">[src]</a></div><a href="#method.index_mut" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/ops/index/trait.IndexMut.html#tymethod.index_mut" class="fnname">index_mut</a>(&mut self, index: I) -> &mut I::<a class="associatedtype" href="https://doc.rust-lang.org/1.59.0/core/slice/index/trait.SliceIndex.html#associatedtype.Output" title="type core::slice::index::SliceIndex::Output">Output</a></h4></div></summary><div class='docblock'><p>Performs the mutable indexing (<code>container[index]</code>) operation. <a href="https://doc.rust-lang.org/1.59.0/core/ops/index/trait.IndexMut.html#tymethod.index_mut">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-IntoIterator" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1958-1973" title="goto source code">[src]</a></div><a href="#impl-IntoIterator" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><div id="associatedtype.IntoIter" class="type trait-impl has-srclink"><a href="#associatedtype.IntoIter" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" class="associatedtype">IntoIter</a> = <a class="struct" href="struct.IntoIter.html" title="struct smallvec::IntoIter">IntoIter</a><A></h4></div></summary><div class='docblock'><p>Which kind of iterator are we turning this into?</p>
|
||
</div></details><details class="rustdoc-toggle" open><summary><div id="associatedtype.Item" class="type trait-impl has-srclink"><a href="#associatedtype.Item" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" class="associatedtype">Item</a> = A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a></h4></div></summary><div class='docblock'><p>The type of the elements being iterated over.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.into_iter" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1961-1972" title="goto source code">[src]</a></div><a href="#method.into_iter" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html#tymethod.into_iter" class="fnname">into_iter</a>(self) -> Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a></h4></div></summary><div class='docblock'><p>Creates an iterator from a value. <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html#tymethod.into_iter">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-IntoIterator-1" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1975-1981" title="goto source code">[src]</a></div><a href="#impl-IntoIterator-1" class="anchor"></a><h3 class="code-header in-band">impl<'a, A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a> for &'a <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><div id="associatedtype.IntoIter-1" class="type trait-impl has-srclink"><a href="#associatedtype.IntoIter-1" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" class="associatedtype">IntoIter</a> = <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.Iter.html" title="struct core::slice::iter::Iter">Iter</a><'a, A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>></h4></div></summary><div class='docblock'><p>Which kind of iterator are we turning this into?</p>
|
||
</div></details><details class="rustdoc-toggle" open><summary><div id="associatedtype.Item-1" class="type trait-impl has-srclink"><a href="#associatedtype.Item-1" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" class="associatedtype">Item</a> = &'a A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a></h4></div></summary><div class='docblock'><p>The type of the elements being iterated over.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.into_iter-1" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1978-1980" title="goto source code">[src]</a></div><a href="#method.into_iter-1" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html#tymethod.into_iter" class="fnname">into_iter</a>(self) -> Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a></h4></div></summary><div class='docblock'><p>Creates an iterator from a value. <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html#tymethod.into_iter">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-IntoIterator-2" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1983-1989" title="goto source code">[src]</a></div><a href="#impl-IntoIterator-2" class="anchor"></a><h3 class="code-header in-band">impl<'a, A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a> for &'a mut <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><div id="associatedtype.IntoIter-2" class="type trait-impl has-srclink"><a href="#associatedtype.IntoIter-2" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" class="associatedtype">IntoIter</a> = <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/slice/iter/struct.IterMut.html" title="struct core::slice::iter::IterMut">IterMut</a><'a, A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>></h4></div></summary><div class='docblock'><p>Which kind of iterator are we turning this into?</p>
|
||
</div></details><details class="rustdoc-toggle" open><summary><div id="associatedtype.Item-2" class="type trait-impl has-srclink"><a href="#associatedtype.Item-2" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" class="associatedtype">Item</a> = &'a mut A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a></h4></div></summary><div class='docblock'><p>The type of the elements being iterated over.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.into_iter-2" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1986-1988" title="goto source code">[src]</a></div><a href="#method.into_iter-2" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html#tymethod.into_iter" class="fnname">into_iter</a>(self) -> Self::<a class="associatedtype" href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a></h4></div></summary><div class='docblock'><p>Creates an iterator from a value. <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html#tymethod.into_iter">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-Ord" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1848-1856" title="goto source code">[src]</a></div><a href="#impl-Ord" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A> <span class="where fmt-newline">where<br> A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>, </span></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.cmp" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1853-1855" title="goto source code">[src]</a></div><a href="#method.cmp" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html#tymethod.cmp" class="fnname">cmp</a>(&self, other: &<a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A>) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a></h4></div></summary><div class='docblock'><p>This method returns an <a href="https://doc.rust-lang.org/1.59.0/core/cmp/enum.Ordering.html" title="Ordering"><code>Ordering</code></a> between <code>self</code> and <code>other</code>. <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html#tymethod.cmp">Read more</a></p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.max" class="method trait-impl has-srclink"><div class="rightside"><span class="since" title="Stable since Rust version 1.21.0">1.21.0</span><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/cmp.rs.html#768-770" title="goto source code">[src]</a></div><a href="#method.max" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html#method.max" class="fnname">max</a>(self, other: Self) -> Self</h4></div></summary><div class='docblock'><p>Compares and returns the maximum of two values. <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html#method.max">Read more</a></p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.min" class="method trait-impl has-srclink"><div class="rightside"><span class="since" title="Stable since Rust version 1.21.0">1.21.0</span><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/cmp.rs.html#788-790" title="goto source code">[src]</a></div><a href="#method.min" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html#method.min" class="fnname">min</a>(self, other: Self) -> Self</h4></div></summary><div class='docblock'><p>Compares and returns the minimum of two values. <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html#method.min">Read more</a></p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.clamp" class="method trait-impl has-srclink"><div class="rightside"><span class="since" title="Stable since Rust version 1.50.0">1.50.0</span><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/cmp.rs.html#813-815" title="goto source code">[src]</a></div><a href="#method.clamp" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html#method.clamp" class="fnname">clamp</a>(self, min: Self, max: Self) -> Self</h4></div></summary><div class='docblock'><p>Restrict a value to a certain interval. <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html#method.clamp">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-PartialEq%3CSmallVec%3CB%3E%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1826-1834" title="goto source code">[src]</a></div><a href="#impl-PartialEq%3CSmallVec%3CB%3E%3E" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>, B: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><<a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><B>> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A> <span class="where fmt-newline">where<br> A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><B::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>>, </span></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.eq" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1831-1833" title="goto source code">[src]</a></div><a href="#method.eq" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialEq.html#tymethod.eq" class="fnname">eq</a>(&self, other: &<a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><B>) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a></h4></div></summary><div class='docblock'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used
|
||
by <code>==</code>. <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.ne" class="method trait-impl has-srclink"><div 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/1.59.0/src/core/cmp.rs.html#219" title="goto source code">[src]</a></div><a href="#method.ne" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialEq.html#method.ne" class="fnname">ne</a>(&self, other: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>Rhs) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a></h4></div></summary><div class='docblock'><p>This method tests for <code>!=</code>.</p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-PartialOrd%3CSmallVec%3CA%3E%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1838-1846" title="goto source code">[src]</a></div><a href="#impl-PartialOrd%3CSmallVec%3CA%3E%3E" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a><<a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A>> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A> <span class="where fmt-newline">where<br> A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a>, </span></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.partial_cmp" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1843-1845" title="goto source code">[src]</a></div><a href="#method.partial_cmp" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialOrd.html#tymethod.partial_cmp" class="fnname">partial_cmp</a>(&self, other: &<a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A>) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="enum" href="https://doc.rust-lang.org/1.59.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>></h4></div></summary><div class='docblock'><p>This method returns an ordering between <code>self</code> and <code>other</code> values if one exists. <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialOrd.html#tymethod.partial_cmp">Read more</a></p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.lt" class="method trait-impl has-srclink"><div 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/1.59.0/src/core/cmp.rs.html#1036" title="goto source code">[src]</a></div><a href="#method.lt" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialOrd.html#method.lt" class="fnname">lt</a>(&self, other: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>Rhs) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a></h4></div></summary><div class='docblock'><p>This method tests less than (for <code>self</code> and <code>other</code>) and is used by the <code><</code> operator. <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialOrd.html#method.lt">Read more</a></p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.le" class="method trait-impl has-srclink"><div 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/1.59.0/src/core/cmp.rs.html#1056" title="goto source code">[src]</a></div><a href="#method.le" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialOrd.html#method.le" class="fnname">le</a>(&self, other: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>Rhs) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a></h4></div></summary><div class='docblock'><p>This method tests less than or equal to (for <code>self</code> and <code>other</code>) and is used by the <code><=</code>
|
||
operator. <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialOrd.html#method.le">Read more</a></p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.gt" class="method trait-impl has-srclink"><div 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/1.59.0/src/core/cmp.rs.html#1079" title="goto source code">[src]</a></div><a href="#method.gt" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialOrd.html#method.gt" class="fnname">gt</a>(&self, other: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>Rhs) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a></h4></div></summary><div class='docblock'><p>This method tests greater than (for <code>self</code> and <code>other</code>) and is used by the <code>></code> operator. <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialOrd.html#method.gt">Read more</a></p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.ge" class="method trait-impl has-srclink"><div 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/1.59.0/src/core/cmp.rs.html#1099" title="goto source code">[src]</a></div><a href="#method.ge" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialOrd.html#method.ge" class="fnname">ge</a>(&self, other: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>Rhs) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.bool.html">bool</a></h4></div></summary><div class='docblock'><p>This method tests greater than or equal to (for <code>self</code> and <code>other</code>) and is used by the <code>>=</code>
|
||
operator. <a href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.PartialOrd.html#method.ge">Read more</a></p>
|
||
</div></details></div></details><div id="impl-Eq" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1836" title="goto source code">[src]</a></div><a href="#impl-Eq" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A> <span class="where fmt-newline">where<br> A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a>, </span></h3></div><div id="impl-Send" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/smallvec/lib.rs.html#1867" title="goto source code">[src]</a></div><a href="#impl-Send" class="anchor"></a><h3 class="code-header in-band">impl<A: <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A> <span class="where fmt-newline">where<br> A::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></h3></div></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><div id="impl-RefUnwindSafe" class="impl has-srclink"><div class="rightside"></div><a href="#impl-RefUnwindSafe" class="anchor"></a><h3 class="code-header in-band">impl<A> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A> <span class="where fmt-newline">where<br> A: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a>,<br> <A as <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>>::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a>, </span></h3></div><div id="impl-Sync" class="impl has-srclink"><div class="rightside"></div><a href="#impl-Sync" class="anchor"></a><h3 class="code-header in-band">impl<A> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A> <span class="where fmt-newline">where<br> A: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>, </span></h3></div><div id="impl-Unpin" class="impl has-srclink"><div class="rightside"></div><a href="#impl-Unpin" class="anchor"></a><h3 class="code-header in-band">impl<A> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A> <span class="where fmt-newline">where<br> A: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>, </span></h3></div><div id="impl-UnwindSafe" class="impl has-srclink"><div class="rightside"></div><a href="#impl-UnwindSafe" class="anchor"></a><h3 class="code-header in-band">impl<A> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.SmallVec.html" title="struct smallvec::SmallVec">SmallVec</a><A> <span class="where fmt-newline">where<br> A: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a>,<br> <A as <a class="trait" href="trait.Array.html" title="trait smallvec::Array">Array</a>>::<a class="associatedtype" href="trait.Array.html#associatedtype.Item" title="type smallvec::Array::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a>, </span></h3></div></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-Any" class="impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/any.rs.html#132-136" title="goto source code">[src]</a></div><a href="#impl-Any" class="anchor"></a><h3 class="code-header in-band">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.59.0/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/1.59.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.type_id" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/any.rs.html#133" title="goto source code">[src]</a></div><a href="#method.type_id" class="anchor"></a><h4 class="code-header">pub fn <a href="https://doc.rust-lang.org/1.59.0/core/any/trait.Any.html#tymethod.type_id" class="fnname">type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></div></summary><div class='docblock'><p>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/1.59.0/core/any/trait.Any.html#tymethod.type_id">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-Borrow%3CT%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/borrow.rs.html#209-214" title="goto source code">[src]</a></div><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/1.59.0/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/1.59.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.borrow-1" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/borrow.rs.html#211" title="goto source code">[src]</a></div><a href="#method.borrow-1" class="anchor"></a><h4 class="code-header">pub fn <a href="https://doc.rust-lang.org/1.59.0/core/borrow/trait.Borrow.html#tymethod.borrow" class="fnname">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&</a>T</h4></div></summary><div class='docblock'><p>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.59.0/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-BorrowMut%3CT%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/borrow.rs.html#218-222" title="goto source code">[src]</a></div><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/1.59.0/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/1.59.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.borrow_mut-1" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/borrow.rs.html#219" title="goto source code">[src]</a></div><a href="#method.borrow_mut-1" class="anchor"></a><h4 class="code-header">pub fn <a href="https://doc.rust-lang.org/1.59.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fnname">borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&mut </a>T</h4></div></summary><div class='docblock'><p>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.59.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-From%3C!%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/convert/mod.rs.html#566-570" title="goto source code">[src]</a></div><a href="#impl-From%3C!%3E" class="anchor"></a><h3 class="code-header in-band">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><<a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.never.html">!</a>> for T</h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.from-3" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/convert/mod.rs.html#567" title="goto source code">[src]</a></div><a href="#method.from-3" class="anchor"></a><h4 class="code-header">pub fn <a href="https://doc.rust-lang.org/1.59.0/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(t: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.never.html">!</a>) -> T</h4></div></summary><div class='docblock'><p>Performs the conversion.</p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-From%3CT%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/convert/mod.rs.html#550-554" title="goto source code">[src]</a></div><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/1.59.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for T</h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.from-4" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/convert/mod.rs.html#551" title="goto source code">[src]</a></div><a href="#method.from-4" class="anchor"></a><h4 class="code-header">pub fn <a href="https://doc.rust-lang.org/1.59.0/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(t: T) -> T</h4></div></summary><div class='docblock'><p>Performs the conversion.</p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-Into%3CU%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/convert/mod.rs.html#538-545" title="goto source code">[src]</a></div><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/1.59.0/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/1.59.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><T>, </span></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.into" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/convert/mod.rs.html#542" title="goto source code">[src]</a></div><a href="#method.into" class="anchor"></a><h4 class="code-header">pub fn <a href="https://doc.rust-lang.org/1.59.0/core/convert/trait.Into.html#tymethod.into" class="fnname">into</a>(self) -> U</h4></div></summary><div class='docblock'><p>Performs the conversion.</p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-ToOwned" class="impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/alloc/borrow.rs.html#84-96" title="goto source code">[src]</a></div><a href="#impl-ToOwned" class="anchor"></a><h3 class="code-header in-band">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.59.0/alloc/borrow/trait.ToOwned.html" title="trait alloc::borrow::ToOwned">ToOwned</a> for T <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, </span></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><div id="associatedtype.Owned" class="type trait-impl has-srclink"><a href="#associatedtype.Owned" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.59.0/alloc/borrow/trait.ToOwned.html#associatedtype.Owned" class="associatedtype">Owned</a> = T</h4></div></summary><div class='docblock'><p>The resulting type after obtaining ownership.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.to_owned" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/alloc/borrow.rs.html#89" title="goto source code">[src]</a></div><a href="#method.to_owned" class="anchor"></a><h4 class="code-header">pub fn <a href="https://doc.rust-lang.org/1.59.0/alloc/borrow/trait.ToOwned.html#tymethod.to_owned" class="fnname">to_owned</a>(&self) -> T</h4></div></summary><div class='docblock'><p>Creates owned data from borrowed data, usually by cloning. <a href="https://doc.rust-lang.org/1.59.0/alloc/borrow/trait.ToOwned.html#tymethod.to_owned">Read more</a></p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.clone_into" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/alloc/borrow.rs.html#93" title="goto source code">[src]</a></div><a href="#method.clone_into" class="anchor"></a><h4 class="code-header">pub fn <a href="https://doc.rust-lang.org/1.59.0/alloc/borrow/trait.ToOwned.html#method.clone_into" class="fnname">clone_into</a>(&self, target: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/core/primitive.reference.html">&mut </a>T)</h4></div></summary><div class="item-info"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>toowned_clone_into</code>)</div></div><div class='docblock'><p>Uses borrowed data to replace owned data, usually by cloning. <a href="https://doc.rust-lang.org/1.59.0/alloc/borrow/trait.ToOwned.html#method.clone_into">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-TryFrom%3CU%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/convert/mod.rs.html#588-597" title="goto source code">[src]</a></div><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/1.59.0/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/1.59.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>, </span></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><div 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/1.59.0/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></h4></div></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><div id="method.try_from" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/convert/mod.rs.html#594" title="goto source code">[src]</a></div><a href="#method.try_from" class="anchor"></a><h4 class="code-header">pub fn <a href="https://doc.rust-lang.org/1.59.0/core/convert/trait.TryFrom.html#tymethod.try_from" class="fnname">try_from</a>(value: U) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <T as <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></div></summary><div class='docblock'><p>Performs the conversion.</p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-TryInto%3CU%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/convert/mod.rs.html#574-583" title="goto source code">[src]</a></div><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/1.59.0/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/1.59.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>, </span></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><div 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/1.59.0/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></h4></div></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><div id="method.try_into" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/convert/mod.rs.html#580" title="goto source code">[src]</a></div><a href="#method.try_into" class="anchor"></a><h4 class="code-header">pub fn <a href="https://doc.rust-lang.org/1.59.0/core/convert/trait.TryInto.html#tymethod.try_into" class="fnname">try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, <U as <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></div></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="smallvec" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.59.0 (9d1b2106e 2022-02-23)" ></div>
|
||
</body></html> |