2393 lines
487 KiB
HTML
2393 lines
487 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="API documentation for the Rust `Vec` struct in crate `nom`."><meta name="keywords" content="rust, rustlang, rust-lang, Vec"><title>nom::lib::std::vec::Vec - Rust</title><link rel="stylesheet" type="text/css" href="../../../../normalize.css"><link rel="stylesheet" type="text/css" href="../../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../../../dark.css"><link rel="stylesheet" type="text/css" href="../../../../light.css" id="themeStyle"><script src="../../../../storage.js"></script><noscript><link rel="stylesheet" href="../../../../noscript.css"></noscript><link rel="shortcut icon" href="../../../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../../../down-arrow.svg");}</style></head><body class="rustdoc struct"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../../../../nom/index.html'><div class='logo-container'><img src='../../../../rust-logo.png' alt='logo'></div></a><p class='location'>Struct Vec</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><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.drain_filter">drain_filter</a><a href="#method.extend_from_slice">extend_from_slice</a><a href="#method.from_raw_parts">from_raw_parts</a><a href="#method.insert">insert</a><a href="#method.into_boxed_slice">into_boxed_slice</a><a href="#method.into_raw_parts">into_raw_parts</a><a href="#method.is_empty">is_empty</a><a href="#method.leak">leak</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.remove_item">remove_item</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_default">resize_default</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">shrink_to</a><a href="#method.shrink_to_fit">shrink_to_fit</a><a href="#method.splice">splice</a><a href="#method.split_off">split_off</a><a href="#method.swap_remove">swap_remove</a><a href="#method.truncate">truncate</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><a class="sidebar-title" href="#deref-methods">Methods from Deref<Target=[T]></a><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.as_mut_ptr-1">as_mut_ptr</a><a href="#method.as_mut_ptr_range">as_mut_ptr_range</a><a href="#method.as_ptr-1">as_ptr</a><a href="#method.as_ptr_range">as_ptr_range</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.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.is_ascii">is_ascii</a><a href="#method.is_empty-1">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-1">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.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_mut">rsplit_mut</a><a href="#method.rsplitn">rsplitn</a><a href="#method.rsplitn_mut">rsplitn_mut</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_at">split_at</a><a href="#method.split_at_mut">split_at_mut</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.swap">swap</a><a href="#method.swap_with_slice">swap_with_slice</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.windows">windows</a></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-AsMut%3C%5BT%5D%3E">AsMut<[T]></a><a href="#impl-AsMut%3CVec%3CT%3E%3E">AsMut<Vec<T>></a><a href="#impl-AsRef%3C%5BT%5D%3E">AsRef<[T]></a><a href="#impl-AsRef%3CVec%3CT%3E%3E">AsRef<Vec<T>></a><a href="#impl-Borrow%3C%5BT%5D%3E">Borrow<[T]></a><a href="#impl-BorrowMut%3C%5BT%5D%3E">BorrowMut<[T]></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%26%27a%20T%3E">Extend<&'a T></a><a href="#impl-Extend%3CT%3E">Extend<T></a><a href="#impl-From%3C%26%27_%20%5BT%5D%3E">From<&'_ [T]></a><a href="#impl-From%3C%26%27_%20mut%20%5BT%5D%3E">From<&'_ mut [T]></a><a href="#impl-From%3C%26%27_%20str%3E">From<&'_ str></a><a href="#impl-From%3C%26%27a%20Vec%3CT%3E%3E">From<&'a Vec<T>></a><a href="#impl-From%3CBinaryHeap%3CT%3E%3E">From<BinaryHeap<T>></a><a href="#impl-From%3CBox%3C%5BT%5D%3E%3E">From<Box<[T]>></a><a href="#impl-From%3CCString%3E">From<CString></a><a href="#impl-From%3CCow%3C%27a%2C%20%5BT%5D%3E%3E">From<Cow<'a, [T]>></a><a href="#impl-From%3CString%3E">From<String></a><a href="#impl-From%3CVec%3CNonZeroU8%3E%3E">From<Vec<NonZeroU8>></a><a href="#impl-From%3CVec%3CT%3E%3E">From<Vec<T>></a><a href="#impl-From%3CVecDeque%3CT%3E%3E">From<VecDeque<T>></a><a href="#impl-FromIterator%3CT%3E">FromIterator<T></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%3C%26%27_%20%5BB%3B%20N%5D%3E">PartialEq<&'_ [B; N]></a><a href="#impl-PartialEq%3C%26%27_%20%5BB%5D%3E">PartialEq<&'_ [B]></a><a href="#impl-PartialEq%3C%26%27_%20mut%20%5BB%5D%3E">PartialEq<&'_ mut [B]></a><a href="#impl-PartialEq%3C%5BB%3B%20N%5D%3E">PartialEq<[B; N]></a><a href="#impl-PartialEq%3CVec%3CB%3E%3E">PartialEq<Vec<B>></a><a href="#impl-PartialOrd%3CVec%3CT%3E%3E">PartialOrd<Vec<T>></a><a href="#impl-Write">Write</a></div><a class="sidebar-title" href="#synthetic-implementations">Auto Trait Implementations</a><div class="sidebar-links"><a href="#impl-RefUnwindSafe">RefUnwindSafe</a><a href="#impl-Send">Send</a><a href="#impl-Sync">Sync</a><a href="#impl-Unpin">Unpin</a><a href="#impl-UnwindSafe">UnwindSafe</a></div><a class="sidebar-title" href="#blanket-implementations">Blanket Implementations</a><div class="sidebar-links"><a href="#impl-Any">Any</a><a href="#impl-Borrow%3CT%3E">Borrow<T></a><a href="#impl-BorrowMut%3CT%3E">BorrowMut<T></a><a href="#impl-From%3CT%3E">From<T></a><a href="#impl-Into%3CU%3E">Into<U></a><a href="#impl-IntoIterator">IntoIterator</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><p class='location'><a href='../../../index.html'>nom</a>::<wbr><a href='../../index.html'>lib</a>::<wbr><a href='../index.html'>std</a>::<wbr><a href='index.html'>vec</a></p><script>window.sidebarCurrent = {name: 'Vec', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../../../../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../../../../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><a id="settings-menu" href="../../../../settings.html"><img src="../../../../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='out-of-band'><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>−</span>]</a></span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#299-302' title='goto source code'>[src]</a></span><span class='in-band'>Struct <a href='../../../index.html'>nom</a>::<wbr><a href='../../index.html'>lib</a>::<wbr><a href='../index.html'>std</a>::<wbr><a href='index.html'>vec</a>::<wbr><a class="struct" href=''>Vec</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class='rust struct'>pub struct Vec<T> { /* fields omitted */ }</pre></div><div class='docblock'><p>A contiguous growable array type, written <code>Vec<T></code> but pronounced 'vector'.</p>
|
||
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">new</span>();
|
||
<span class="ident">vec</span>.<span class="ident">push</span>(<span class="number">1</span>);
|
||
<span class="ident">vec</span>.<span class="ident">push</span>(<span class="number">2</span>);
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>.<span class="ident">len</span>(), <span class="number">2</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>[<span class="number">0</span>], <span class="number">1</span>);
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>.<span class="ident">pop</span>(), <span class="prelude-val">Some</span>(<span class="number">2</span>));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>.<span class="ident">len</span>(), <span class="number">1</span>);
|
||
|
||
<span class="ident">vec</span>[<span class="number">0</span>] <span class="op">=</span> <span class="number">7</span>;
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>[<span class="number">0</span>], <span class="number">7</span>);
|
||
|
||
<span class="ident">vec</span>.<span class="ident">extend</span>([<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].<span class="ident">iter</span>().<span class="ident">copied</span>());
|
||
|
||
<span class="kw">for</span> <span class="ident">x</span> <span class="kw">in</span> <span class="kw-2">&</span><span class="ident">vec</span> {
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">x</span>);
|
||
}
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>, [<span class="number">7</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]);</pre></div>
|
||
<p>The <a href="../../std/macro.vec.html"><code>vec!</code></a> macro is provided to make initialization more convenient:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
<span class="ident">vec</span>.<span class="ident">push</span>(<span class="number">4</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>]);</pre></div>
|
||
<p>It can also initialize each element of a <code>Vec<T></code> with a given value.
|
||
This may be more efficient than performing allocation and initialization
|
||
in separate steps, especially when initializing a vector of zeros:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">0</span>; <span class="number">5</span>];
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</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="comment">// The following is equivalent, but potentially slower:</span>
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec1</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">with_capacity</span>(<span class="number">5</span>);
|
||
<span class="ident">vec1</span>.<span class="ident">resize</span>(<span class="number">5</span>, <span class="number">0</span>);</pre></div>
|
||
<p>Use a <code>Vec<T></code> as an efficient stack:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">stack</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">new</span>();
|
||
|
||
<span class="ident">stack</span>.<span class="ident">push</span>(<span class="number">1</span>);
|
||
<span class="ident">stack</span>.<span class="ident">push</span>(<span class="number">2</span>);
|
||
<span class="ident">stack</span>.<span class="ident">push</span>(<span class="number">3</span>);
|
||
|
||
<span class="kw">while</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">top</span>) <span class="op">=</span> <span class="ident">stack</span>.<span class="ident">pop</span>() {
|
||
<span class="comment">// Prints 3, 2, 1</span>
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">top</span>);
|
||
}</pre></div>
|
||
<h1 id="indexing" class="section-header"><a href="#indexing">Indexing</a></h1>
|
||
<p>The <code>Vec</code> type allows to access values by index, because it implements the
|
||
<a href="../../std/ops/trait.Index.html"><code>Index</code></a> trait. An example will be more explicit:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">0</span>, <span class="number">2</span>, <span class="number">4</span>, <span class="number">6</span>];
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">v</span>[<span class="number">1</span>]); <span class="comment">// it will display '2'</span></pre></div>
|
||
<p>However be careful: if you try to access an index which isn't in the <code>Vec</code>,
|
||
your software will panic! You cannot do this:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">0</span>, <span class="number">2</span>, <span class="number">4</span>, <span class="number">6</span>];
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">v</span>[<span class="number">6</span>]); <span class="comment">// it will panic!</span></pre></div>
|
||
<p>Use <a href="../../std/vec/struct.Vec.html#method.get"><code>get</code></a> and <a href="../../std/vec/struct.Vec.html#method.get_mut"><code>get_mut</code></a> if you want to check whether the index is in
|
||
the <code>Vec</code>.</p>
|
||
<h1 id="slicing" class="section-header"><a href="#slicing">Slicing</a></h1>
|
||
<p>A <code>Vec</code> can be mutable. Slices, on the other hand, are read-only objects.
|
||
To get a slice, use <code>&</code>. Example:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">fn</span> <span class="ident">read_slice</span>(<span class="ident">slice</span>: <span class="kw-2">&</span>[<span class="ident">usize</span>]) {
|
||
<span class="comment">// ...</span>
|
||
}
|
||
|
||
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">0</span>, <span class="number">1</span>];
|
||
<span class="ident">read_slice</span>(<span class="kw-2">&</span><span class="ident">v</span>);
|
||
|
||
<span class="comment">// ... and that's all!</span>
|
||
<span class="comment">// you can also do it like this:</span>
|
||
<span class="kw">let</span> <span class="ident">x</span> : <span class="kw-2">&</span>[<span class="ident">usize</span>] <span class="op">=</span> <span class="kw-2">&</span><span class="ident">v</span>;</pre></div>
|
||
<p>In Rust, it's more common to pass slices as arguments rather than vectors
|
||
when you just want to provide read access. The same goes for <a href="../../std/string/struct.String.html"><code>String</code></a> and
|
||
<a href="../../std/primitive.str.html"><code>&str</code></a>.</p>
|
||
<h1 id="capacity-and-reallocation" class="section-header"><a href="#capacity-and-reallocation">Capacity and reallocation</a></h1>
|
||
<p>The capacity of a vector is the amount of space allocated for any future
|
||
elements that will be added onto the vector. This is not to be confused with
|
||
the <em>length</em> of a vector, which specifies the number of actual elements
|
||
within the vector. If a vector's length exceeds its capacity, its capacity
|
||
will automatically be increased, but its elements will have to be
|
||
reallocated.</p>
|
||
<p>For example, a vector with capacity 10 and length 0 would be an empty vector
|
||
with space for 10 more elements. Pushing 10 or fewer elements onto the
|
||
vector will not change its capacity or cause reallocation to occur. However,
|
||
if the vector's length is increased to 11, it will have to reallocate, which
|
||
can be slow. For this reason, it is recommended to use <a href="../../std/vec/struct.Vec.html#method.with_capacity"><code>Vec::with_capacity</code></a>
|
||
whenever possible to specify how big the vector is expected to get.</p>
|
||
<h1 id="guarantees" class="section-header"><a href="#guarantees">Guarantees</a></h1>
|
||
<p>Due to its incredibly fundamental nature, <code>Vec</code> makes a lot of guarantees
|
||
about its design. This ensures that it's as low-overhead as possible in
|
||
the general case, and can be correctly manipulated in primitive ways
|
||
by unsafe code. Note that these guarantees refer to an unqualified <code>Vec<T></code>.
|
||
If additional type parameters are added (e.g., to support custom allocators),
|
||
overriding their defaults may change the behavior.</p>
|
||
<p>Most fundamentally, <code>Vec</code> is and always will be a (pointer, capacity, length)
|
||
triplet. No more, no less. The order of these fields is completely
|
||
unspecified, and you should use the appropriate methods to modify these.
|
||
The pointer will never be null, so this type is null-pointer-optimized.</p>
|
||
<p>However, the pointer may not actually point to allocated memory. In particular,
|
||
if you construct a <code>Vec</code> with capacity 0 via <a href="../../std/vec/struct.Vec.html#method.new"><code>Vec::new</code></a>, <a href="../../std/macro.vec.html"><code>vec![]</code></a>,
|
||
<a href="../../std/vec/struct.Vec.html#method.with_capacity"><code>Vec::with_capacity(0)</code></a>, or by calling <a href="../../std/vec/struct.Vec.html#method.shrink_to_fit"><code>shrink_to_fit</code></a>
|
||
on an empty Vec, it will not allocate memory. Similarly, if you store zero-sized
|
||
types inside a <code>Vec</code>, it will not allocate space for them. <em>Note that in this case
|
||
the <code>Vec</code> may not report a <a href="../../std/vec/struct.Vec.html#method.capacity"><code>capacity</code></a> of 0</em>. <code>Vec</code> will allocate if and only
|
||
if <a href="../../std/mem/fn.size_of.html"><code>mem::size_of::<T></code></a><code>() * capacity() > 0</code>. In general, <code>Vec</code>'s allocation
|
||
details are very subtle — if you intend to allocate memory using a <code>Vec</code>
|
||
and use it for something else (either to pass to unsafe code, or to build your
|
||
own memory-backed collection), be sure to deallocate this memory by using
|
||
<code>from_raw_parts</code> to recover the <code>Vec</code> and then dropping it.</p>
|
||
<p>If a <code>Vec</code> <em>has</em> allocated memory, then the memory it points to is on the heap
|
||
(as defined by the allocator Rust is configured to use by default), and its
|
||
pointer points to <a href="../../std/vec/struct.Vec.html#method.len"><code>len</code></a> initialized, contiguous elements in order (what
|
||
you would see if you coerced it to a slice), followed by <a href="../../std/vec/struct.Vec.html#method.capacity"><code>capacity</code></a><code>-</code><a href="../../std/vec/struct.Vec.html#method.len"><code>len</code></a> logically uninitialized, contiguous elements.</p>
|
||
<p><code>Vec</code> will never perform a "small optimization" where elements are actually
|
||
stored on the stack for two reasons:</p>
|
||
<ul>
|
||
<li>
|
||
<p>It would make it more difficult for unsafe code to correctly manipulate
|
||
a <code>Vec</code>. The contents of a <code>Vec</code> wouldn't have a stable address if it were
|
||
only moved, and it would be more difficult to determine if a <code>Vec</code> had
|
||
actually allocated memory.</p>
|
||
</li>
|
||
<li>
|
||
<p>It would penalize the general case, incurring an additional branch
|
||
on every access.</p>
|
||
</li>
|
||
</ul>
|
||
<p><code>Vec</code> will never automatically shrink itself, even if completely empty. This
|
||
ensures no unnecessary allocations or deallocations occur. Emptying a <code>Vec</code>
|
||
and then filling it back up to the same <a href="../../std/vec/struct.Vec.html#method.len"><code>len</code></a> should incur no calls to
|
||
the allocator. If you wish to free up unused memory, use
|
||
<a href="../../std/vec/struct.Vec.html#method.shrink_to_fit"><code>shrink_to_fit</code></a>.</p>
|
||
<p><a href="../../std/vec/struct.Vec.html#method.push"><code>push</code></a> and <a href="../../std/vec/struct.Vec.html#method.insert"><code>insert</code></a> will never (re)allocate if the reported capacity is
|
||
sufficient. <a href="../../std/vec/struct.Vec.html#method.push"><code>push</code></a> and <a href="../../std/vec/struct.Vec.html#method.insert"><code>insert</code></a> <em>will</em> (re)allocate if
|
||
<a href="../../std/vec/struct.Vec.html#method.len"><code>len</code></a><code>==</code><a href="../../std/vec/struct.Vec.html#method.capacity"><code>capacity</code></a>. That is, the reported capacity is completely
|
||
accurate, and can be relied on. It can even be used to manually free the memory
|
||
allocated by a <code>Vec</code> if desired. Bulk insertion methods <em>may</em> reallocate, even
|
||
when not necessary.</p>
|
||
<p><code>Vec</code> does not guarantee any particular growth strategy when reallocating
|
||
when full, nor when <a href="../../std/vec/struct.Vec.html#method.reserve"><code>reserve</code></a> is called. The current strategy is basic
|
||
and it may prove desirable to use a non-constant growth factor. Whatever
|
||
strategy is used will of course guarantee <code>O(1)</code> amortized <a href="../../std/vec/struct.Vec.html#method.push"><code>push</code></a>.</p>
|
||
<p><code>vec![x; n]</code>, <code>vec![a, b, c, d]</code>, and
|
||
<a href="../../std/vec/struct.Vec.html#method.with_capacity"><code>Vec::with_capacity(n)</code></a>, will all produce a <code>Vec</code>
|
||
with exactly the requested capacity. If <a href="../../std/vec/struct.Vec.html#method.len"><code>len</code></a><code>==</code><a href="../../std/vec/struct.Vec.html#method.capacity"><code>capacity</code></a>,
|
||
(as is the case for the <a href="../../std/macro.vec.html"><code>vec!</code></a> macro), then a <code>Vec<T></code> can be converted to
|
||
and from a <a href="../../std/boxed/struct.Box.html"><code>Box<[T]></code></a> without reallocating or moving the elements.</p>
|
||
<p><code>Vec</code> will not specifically overwrite any data that is removed from it,
|
||
but also won't specifically preserve it. Its uninitialized memory is
|
||
scratch space that it may use however it wants. It will generally just do
|
||
whatever is most efficient or otherwise easy to implement. Do not rely on
|
||
removed data to be erased for security purposes. Even if you drop a <code>Vec</code>, its
|
||
buffer may simply be reused by another <code>Vec</code>. Even if you zero a <code>Vec</code>'s memory
|
||
first, that may not actually happen because the optimizer does not consider
|
||
this a side-effect that must be preserved. There is one case which we will
|
||
not break, however: using <code>unsafe</code> code to write to the excess capacity,
|
||
and then increasing the length to match, is always valid.</p>
|
||
<p><code>Vec</code> does not currently guarantee the order in which elements are dropped.
|
||
The order has changed in the past and may change again.</p>
|
||
</div><h2 id='methods' class='small-section-header'>Methods<a href='#methods' class='anchor'></a></h2><h3 id='impl' class='impl'><code class='in-band'>impl<T> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#308-1470' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.new' class="method"><code id='new.v'>pub const fn <a href='#method.new' class='fnname'>new</a>() -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#322-324' title='goto source code'>[src]</a></h4><div class='docblock'><p>Constructs a new, empty <code>Vec<T></code>.</p>
|
||
<p>The vector will not allocate until elements are pushed onto it.</p>
|
||
<h1 id="examples-1" class="section-header"><a href="#examples-1">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span>: <span class="ident">Vec</span><span class="op"><</span><span class="ident">i32</span><span class="op">></span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">new</span>();</pre></div>
|
||
</div><h4 id='method.with_capacity' class="method"><code id='with_capacity.v'>pub fn <a href='#method.with_capacity' class='fnname'>with_capacity</a>(capacity: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#356-358' title='goto source code'>[src]</a></h4><div class='docblock'><p>Constructs a new, empty <code>Vec<T></code> with the specified capacity.</p>
|
||
<p>The vector will be able to hold exactly <code>capacity</code> elements without
|
||
reallocating. If <code>capacity</code> is 0, the vector will not allocate.</p>
|
||
<p>It is important to note that although the returned vector has the
|
||
<em>capacity</em> specified, the vector will have a zero <em>length</em>. For an
|
||
explanation of the difference between length and capacity, see
|
||
<em><a href="#capacity-and-reallocation">Capacity and reallocation</a></em>.</p>
|
||
<h1 id="examples-2" class="section-header"><a href="#examples-2">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">with_capacity</span>(<span class="number">10</span>);
|
||
|
||
<span class="comment">// The vector contains no items, even though it has capacity for more</span>
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>.<span class="ident">len</span>(), <span class="number">0</span>);
|
||
|
||
<span class="comment">// These are all done without reallocating...</span>
|
||
<span class="kw">for</span> <span class="ident">i</span> <span class="kw">in</span> <span class="number">0</span>..<span class="number">10</span> {
|
||
<span class="ident">vec</span>.<span class="ident">push</span>(<span class="ident">i</span>);
|
||
}
|
||
|
||
<span class="comment">// ...but this may make the vector reallocate</span>
|
||
<span class="ident">vec</span>.<span class="ident">push</span>(<span class="number">11</span>);</pre></div>
|
||
</div><h4 id='method.into_raw_parts' class="method"><code id='into_raw_parts.v'>pub fn <a href='#method.into_raw_parts' class='fnname'>into_raw_parts</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.pointer.html">*mut T</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#393-396' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><details><summary><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>vec_into_raw_parts</code>)</summary><p>new API</p>
|
||
</details></div></div><div class='docblock'><p>Decomposes a <code>Vec<T></code> into its raw components.</p>
|
||
<p>Returns the raw pointer to the underlying data, the length of
|
||
the vector (in elements), and the allocated capacity of the
|
||
data (in elements). These are the same arguments in the same
|
||
order as the arguments to <a href="#method.from_raw_parts"><code>from_raw_parts</code></a>.</p>
|
||
<p>After calling this function, the caller is responsible for the
|
||
memory previously managed by the <code>Vec</code>. The only way to do
|
||
this is to convert the raw pointer, length, and capacity back
|
||
into a <code>Vec</code> with the <a href="#method.from_raw_parts"><code>from_raw_parts</code></a> function, allowing
|
||
the destructor to perform the cleanup.</p>
|
||
<h1 id="examples-3" class="section-header"><a href="#examples-3">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="attribute">#![<span class="ident">feature</span>(<span class="ident">vec_into_raw_parts</span>)]</span>
|
||
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op"><</span><span class="ident">i32</span><span class="op">></span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="op">-</span><span class="number">1</span>, <span class="number">0</span>, <span class="number">1</span>];
|
||
|
||
<span class="kw">let</span> (<span class="ident">ptr</span>, <span class="ident">len</span>, <span class="ident">cap</span>) <span class="op">=</span> <span class="ident">v</span>.<span class="ident">into_raw_parts</span>();
|
||
|
||
<span class="kw">let</span> <span class="ident">rebuilt</span> <span class="op">=</span> <span class="kw">unsafe</span> {
|
||
<span class="comment">// We can now make changes to the components, such as</span>
|
||
<span class="comment">// transmuting the raw pointer to a compatible type.</span>
|
||
<span class="kw">let</span> <span class="ident">ptr</span> <span class="op">=</span> <span class="ident">ptr</span> <span class="kw">as</span> <span class="kw-2">*</span><span class="kw-2">mut</span> <span class="ident">u32</span>;
|
||
|
||
<span class="ident">Vec</span>::<span class="ident">from_raw_parts</span>(<span class="ident">ptr</span>, <span class="ident">len</span>, <span class="ident">cap</span>)
|
||
};
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">rebuilt</span>, [<span class="number">4294967295</span>, <span class="number">0</span>, <span class="number">1</span>]);</pre></div>
|
||
</div><h4 id='method.from_raw_parts' class="method"><code id='from_raw_parts.v'>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/nightly/std/primitive.pointer.html">*mut T</a>, <br> length: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <br> capacity: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a><br>) -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#461-463' title='goto source code'>[src]</a></h4><div class='docblock'><p>Creates a <code>Vec<T></code> directly from the raw components of another vector.</p>
|
||
<h1 id="safety" class="section-header"><a href="#safety">Safety</a></h1>
|
||
<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 <a href="../../std/string/struct.String.html"><code>String</code></a>/<code>Vec<T></code>
|
||
(at least, it's highly likely to be incorrect if it wasn't).</li>
|
||
<li><code>T</code> needs to have the same size and alignment as what <code>ptr</code> was allocated with.
|
||
(<code>T</code> having a less strict alignment is not sufficient, the alignment really
|
||
needs to be equal to satsify the <a href="../../alloc/alloc/trait.GlobalAlloc.html#tymethod.dealloc"><code>dealloc</code></a> requirement that memory must be
|
||
allocated and deallocated with the same layout.)</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. For example it is <strong>not</strong> safe
|
||
to build a <code>Vec<u8></code> from a pointer to a C <code>char</code> array with length <code>size_t</code>.
|
||
It's also not safe to build one from a <code>Vec<u16></code> and its length, because
|
||
the allocator cares about the alignment, and these two types have different
|
||
alignments. The buffer was allocated with alignment 2 (for <code>u16</code>), but after
|
||
turning it into a <code>Vec<u8></code> it'll be deallocated with alignment 1.</p>
|
||
<p>The ownership of <code>ptr</code> is effectively transferred to the
|
||
<code>Vec<T></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>
|
||
<h1 id="examples-4" class="section-header"><a href="#examples-4">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">ptr</span>;
|
||
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">mem</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
|
||
<span class="comment">// Prevent running `v`'s destructor so we are in complete control</span>
|
||
<span class="comment">// of the allocation.</span>
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> <span class="ident">mem</span>::<span class="ident">ManuallyDrop</span>::<span class="ident">new</span>(<span class="ident">v</span>);
|
||
|
||
<span class="comment">// Pull out the various important pieces of information about `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">unsafe</span> {
|
||
<span class="comment">// Overwrite memory with 4, 5, 6</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="kw">as</span> <span class="ident">isize</span> {
|
||
<span class="ident">ptr</span>::<span class="ident">write</span>(<span class="ident">p</span>.<span class="ident">offset</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 Vec</span>
|
||
<span class="kw">let</span> <span class="ident">rebuilt</span> <span class="op">=</span> <span class="ident">Vec</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="macro">!</span>(<span class="ident">rebuilt</span>, [<span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]);
|
||
}</pre></div>
|
||
</div><h4 id='method.capacity' class="method"><code id='capacity.v'>pub fn <a href='#method.capacity' class='fnname'>capacity</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#476-478' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns the number of elements the vector can hold without
|
||
reallocating.</p>
|
||
<h1 id="examples-5" class="section-header"><a href="#examples-5">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">vec</span>: <span class="ident">Vec</span><span class="op"><</span><span class="ident">i32</span><span class="op">></span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">with_capacity</span>(<span class="number">10</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>.<span class="ident">capacity</span>(), <span class="number">10</span>);</pre></div>
|
||
</div><h4 id='method.reserve' class="method"><code id='reserve.v'>pub fn <a href='#method.reserve' class='fnname'>reserve</a>(&mut self, additional: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>)</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#498-500' title='goto source code'>[src]</a></h4><div class='docblock'><p>Reserves capacity for at least <code>additional</code> more elements to be inserted
|
||
in the given <code>Vec<T></code>. The collection may reserve more space to avoid
|
||
frequent reallocations. After calling <code>reserve</code>, capacity will be
|
||
greater than or equal to <code>self.len() + additional</code>. Does nothing if
|
||
capacity is already sufficient.</p>
|
||
<h1 id="panics" class="section-header"><a href="#panics">Panics</a></h1>
|
||
<p>Panics if the new capacity overflows <code>usize</code>.</p>
|
||
<h1 id="examples-6" class="section-header"><a href="#examples-6">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>];
|
||
<span class="ident">vec</span>.<span class="ident">reserve</span>(<span class="number">10</span>);
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">vec</span>.<span class="ident">capacity</span>() <span class="op">></span><span class="op">=</span> <span class="number">11</span>);</pre></div>
|
||
</div><h4 id='method.reserve_exact' class="method"><code id='reserve_exact.v'>pub fn <a href='#method.reserve_exact' class='fnname'>reserve_exact</a>(&mut self, additional: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>)</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#523-525' title='goto source code'>[src]</a></h4><div class='docblock'><p>Reserves the minimum capacity for exactly <code>additional</code> more elements to
|
||
be inserted in the given <code>Vec<T></code>. After calling <code>reserve_exact</code>,
|
||
capacity will be greater than or equal to <code>self.len() + additional</code>.
|
||
Does nothing if the capacity is already sufficient.</p>
|
||
<p>Note that the allocator may give the collection more space than it
|
||
requests. Therefore, capacity can not be relied upon to be precisely
|
||
minimal. Prefer <code>reserve</code> if future insertions are expected.</p>
|
||
<h1 id="panics-1" class="section-header"><a href="#panics-1">Panics</a></h1>
|
||
<p>Panics if the new capacity overflows <code>usize</code>.</p>
|
||
<h1 id="examples-7" class="section-header"><a href="#examples-7">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>];
|
||
<span class="ident">vec</span>.<span class="ident">reserve_exact</span>(<span class="number">10</span>);
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">vec</span>.<span class="ident">capacity</span>() <span class="op">></span><span class="op">=</span> <span class="number">11</span>);</pre></div>
|
||
</div><h4 id='method.try_reserve' class="method"><code id='try_reserve.v'>pub fn <a href='#method.try_reserve' class='fnname'>try_reserve</a>(&mut self, additional: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Result.html" title="enum nom::lib::std::prelude::v1::v1::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="enum" href="../../../../nom/lib/std/collections/enum.TryReserveError.html" title="enum nom::lib::std::collections::TryReserveError">TryReserveError</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#560-562' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><details><summary><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>try_reserve</code>)</summary><p>new API</p>
|
||
</details></div></div><div class='docblock'><p>Tries to reserve capacity for at least <code>additional</code> more elements to be inserted
|
||
in the given <code>Vec<T></code>. The collection may reserve more space to avoid
|
||
frequent reallocations. After calling <code>reserve</code>, capacity will be
|
||
greater than or equal to <code>self.len() + additional</code>. Does nothing if
|
||
capacity is already sufficient.</p>
|
||
<h1 id="errors" class="section-header"><a href="#errors">Errors</a></h1>
|
||
<p>If the capacity overflows, or the allocator reports a failure, then an error
|
||
is returned.</p>
|
||
<h1 id="examples-8" class="section-header"><a href="#examples-8">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="attribute">#![<span class="ident">feature</span>(<span class="ident">try_reserve</span>)]</span>
|
||
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">TryReserveError</span>;
|
||
|
||
<span class="kw">fn</span> <span class="ident">process_data</span>(<span class="ident">data</span>: <span class="kw-2">&</span>[<span class="ident">u32</span>]) <span class="op">-</span><span class="op">></span> <span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">Vec</span><span class="op"><</span><span class="ident">u32</span><span class="op">></span>, <span class="ident">TryReserveError</span><span class="op">></span> {
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">output</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">new</span>();
|
||
|
||
<span class="comment">// Pre-reserve the memory, exiting if we can't</span>
|
||
<span class="ident">output</span>.<span class="ident">try_reserve</span>(<span class="ident">data</span>.<span class="ident">len</span>())<span class="question-mark">?</span>;
|
||
|
||
<span class="comment">// Now we know this can't OOM in the middle of our complex work</span>
|
||
<span class="ident">output</span>.<span class="ident">extend</span>(<span class="ident">data</span>.<span class="ident">iter</span>().<span class="ident">map</span>(<span class="op">|</span><span class="kw-2">&</span><span class="ident">val</span><span class="op">|</span> {
|
||
<span class="ident">val</span> <span class="op">*</span> <span class="number">2</span> <span class="op">+</span> <span class="number">5</span> <span class="comment">// very complicated</span>
|
||
}));
|
||
|
||
<span class="prelude-val">Ok</span>(<span class="ident">output</span>)
|
||
}</pre></div>
|
||
</div><h4 id='method.try_reserve_exact' class="method"><code id='try_reserve_exact.v'>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/nightly/std/primitive.usize.html">usize</a><br>) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Result.html" title="enum nom::lib::std::prelude::v1::v1::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="enum" href="../../../../nom/lib/std/collections/enum.TryReserveError.html" title="enum nom::lib::std::collections::TryReserveError">TryReserveError</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#600-602' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><details><summary><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>try_reserve</code>)</summary><p>new API</p>
|
||
</details></div></div><div class='docblock'><p>Tries to reserves the minimum capacity for exactly <code>additional</code> more elements to
|
||
be inserted in the given <code>Vec<T></code>. After calling <code>reserve_exact</code>,
|
||
capacity will be greater than or equal to <code>self.len() + additional</code>.
|
||
Does nothing if the capacity is already sufficient.</p>
|
||
<p>Note that the allocator may give the collection more space than it
|
||
requests. Therefore, capacity can not be relied upon to be precisely
|
||
minimal. Prefer <code>reserve</code> if future insertions are expected.</p>
|
||
<h1 id="errors-1" class="section-header"><a href="#errors-1">Errors</a></h1>
|
||
<p>If the capacity overflows, or the allocator reports a failure, then an error
|
||
is returned.</p>
|
||
<h1 id="examples-9" class="section-header"><a href="#examples-9">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="attribute">#![<span class="ident">feature</span>(<span class="ident">try_reserve</span>)]</span>
|
||
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">TryReserveError</span>;
|
||
|
||
<span class="kw">fn</span> <span class="ident">process_data</span>(<span class="ident">data</span>: <span class="kw-2">&</span>[<span class="ident">u32</span>]) <span class="op">-</span><span class="op">></span> <span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">Vec</span><span class="op"><</span><span class="ident">u32</span><span class="op">></span>, <span class="ident">TryReserveError</span><span class="op">></span> {
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">output</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">new</span>();
|
||
|
||
<span class="comment">// Pre-reserve the memory, exiting if we can't</span>
|
||
<span class="ident">output</span>.<span class="ident">try_reserve</span>(<span class="ident">data</span>.<span class="ident">len</span>())<span class="question-mark">?</span>;
|
||
|
||
<span class="comment">// Now we know this can't OOM in the middle of our complex work</span>
|
||
<span class="ident">output</span>.<span class="ident">extend</span>(<span class="ident">data</span>.<span class="ident">iter</span>().<span class="ident">map</span>(<span class="op">|</span><span class="kw-2">&</span><span class="ident">val</span><span class="op">|</span> {
|
||
<span class="ident">val</span> <span class="op">*</span> <span class="number">2</span> <span class="op">+</span> <span class="number">5</span> <span class="comment">// very complicated</span>
|
||
}));
|
||
|
||
<span class="prelude-val">Ok</span>(<span class="ident">output</span>)
|
||
}</pre></div>
|
||
</div><h4 id='method.shrink_to_fit' class="method"><code id='shrink_to_fit.v'>pub fn <a href='#method.shrink_to_fit' class='fnname'>shrink_to_fit</a>(&mut self)</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#619-623' title='goto source code'>[src]</a></h4><div class='docblock'><p>Shrinks the capacity of the vector as much as possible.</p>
|
||
<p>It will drop down as close as possible to the length but the allocator
|
||
may still inform the vector that there is space for a few more elements.</p>
|
||
<h1 id="examples-10" class="section-header"><a href="#examples-10">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">with_capacity</span>(<span class="number">10</span>);
|
||
<span class="ident">vec</span>.<span class="ident">extend</span>([<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].<span class="ident">iter</span>().<span class="ident">cloned</span>());
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>.<span class="ident">capacity</span>(), <span class="number">10</span>);
|
||
<span class="ident">vec</span>.<span class="ident">shrink_to_fit</span>();
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">vec</span>.<span class="ident">capacity</span>() <span class="op">></span><span class="op">=</span> <span class="number">3</span>);</pre></div>
|
||
</div><h4 id='method.shrink_to' class="method"><code id='shrink_to.v'>pub fn <a href='#method.shrink_to' class='fnname'>shrink_to</a>(&mut self, min_capacity: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>)</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#648-650' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><details><summary><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>shrink_to</code>)</summary><p>new API</p>
|
||
</details></div></div><div class='docblock'><p>Shrinks the capacity of the vector with a lower bound.</p>
|
||
<p>The capacity will remain at least as large as both the length
|
||
and the supplied value.</p>
|
||
<h1 id="panics-2" class="section-header"><a href="#panics-2">Panics</a></h1>
|
||
<p>Panics if the current capacity is smaller than the supplied
|
||
minimum capacity.</p>
|
||
<h1 id="examples-11" class="section-header"><a href="#examples-11">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="attribute">#![<span class="ident">feature</span>(<span class="ident">shrink_to</span>)]</span>
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">with_capacity</span>(<span class="number">10</span>);
|
||
<span class="ident">vec</span>.<span class="ident">extend</span>([<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].<span class="ident">iter</span>().<span class="ident">cloned</span>());
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>.<span class="ident">capacity</span>(), <span class="number">10</span>);
|
||
<span class="ident">vec</span>.<span class="ident">shrink_to</span>(<span class="number">4</span>);
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">vec</span>.<span class="ident">capacity</span>() <span class="op">></span><span class="op">=</span> <span class="number">4</span>);
|
||
<span class="ident">vec</span>.<span class="ident">shrink_to</span>(<span class="number">0</span>);
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">vec</span>.<span class="ident">capacity</span>() <span class="op">></span><span class="op">=</span> <span class="number">3</span>);</pre></div>
|
||
</div><h4 id='method.into_boxed_slice' class="method"><code id='into_boxed_slice.v'>pub fn <a href='#method.into_boxed_slice' class='fnname'>into_boxed_slice</a>(self) -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Box.html" title="struct nom::lib::std::prelude::v1::v1::Box">Box</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#677-684' title='goto source code'>[src]</a></h4><div class='docblock'><p>Converts the vector into <a href="../../std/boxed/struct.Box.html"><code>Box<[T]></code></a>.</p>
|
||
<p>Note that this will drop any excess capacity.</p>
|
||
<h1 id="examples-12" class="section-header"><a href="#examples-12">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
|
||
<span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> <span class="ident">v</span>.<span class="ident">into_boxed_slice</span>();</pre></div>
|
||
<p>Any excess capacity is removed:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">with_capacity</span>(<span class="number">10</span>);
|
||
<span class="ident">vec</span>.<span class="ident">extend</span>([<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].<span class="ident">iter</span>().<span class="ident">cloned</span>());
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>.<span class="ident">capacity</span>(), <span class="number">10</span>);
|
||
<span class="kw">let</span> <span class="ident">slice</span> <span class="op">=</span> <span class="ident">vec</span>.<span class="ident">into_boxed_slice</span>();
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">slice</span>.<span class="ident">into_vec</span>().<span class="ident">capacity</span>(), <span class="number">3</span>);</pre></div>
|
||
</div><h4 id='method.truncate' class="method"><code id='truncate.v'>pub fn <a href='#method.truncate' class='fnname'>truncate</a>(&mut self, len: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>)</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#729-745' title='goto source code'>[src]</a></h4><div class='docblock'><p>Shortens the vector, keeping the first <code>len</code> elements and dropping
|
||
the rest.</p>
|
||
<p>If <code>len</code> is greater than the vector's current length, this has no
|
||
effect.</p>
|
||
<p>The <a href="#method.drain"><code>drain</code></a> method can emulate <code>truncate</code>, but causes the excess
|
||
elements to be returned instead of dropped.</p>
|
||
<p>Note that this method has no effect on the allocated capacity
|
||
of the vector.</p>
|
||
<h1 id="examples-13" class="section-header"><a href="#examples-13">Examples</a></h1>
|
||
<p>Truncating a five element vector to two elements:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</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">vec</span>.<span class="ident">truncate</span>(<span class="number">2</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>, [<span class="number">1</span>, <span class="number">2</span>]);</pre></div>
|
||
<p>No truncation occurs when <code>len</code> is greater than the vector's current
|
||
length:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
<span class="ident">vec</span>.<span class="ident">truncate</span>(<span class="number">8</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]);</pre></div>
|
||
<p>Truncating when <code>len == 0</code> is equivalent to calling the <a href="#method.clear"><code>clear</code></a>
|
||
method.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
<span class="ident">vec</span>.<span class="ident">truncate</span>(<span class="number">0</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>, []);</pre></div>
|
||
</div><h4 id='method.as_slice' class="method"><code id='as_slice.v'>pub fn <a href='#method.as_slice' class='fnname'>as_slice</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[T]</a></code><span class='since' title='Stable since Rust version 1.7.0'>1.7.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#760-762' title='goto source code'>[src]</a></h4><div class='docblock'><p>Extracts a slice containing the entire vector.</p>
|
||
<p>Equivalent to <code>&s[..]</code>.</p>
|
||
<h1 id="examples-14" class="section-header"><a href="#examples-14">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">io</span>::{<span class="self">self</span>, <span class="ident">Write</span>};
|
||
<span class="kw">let</span> <span class="ident">buffer</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">8</span>];
|
||
<span class="ident">io</span>::<span class="ident">sink</span>().<span class="ident">write</span>(<span class="ident">buffer</span>.<span class="ident">as_slice</span>()).<span class="ident">unwrap</span>();</pre></div>
|
||
</div><h4 id='method.as_mut_slice' class="method"><code id='as_mut_slice.v'>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/nightly/std/primitive.slice.html">&mut [T]</a></code><span class='since' title='Stable since Rust version 1.7.0'>1.7.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#777-779' title='goto source code'>[src]</a></h4><div class='docblock'><p>Extracts a mutable slice of the entire vector.</p>
|
||
<p>Equivalent to <code>&mut s[..]</code>.</p>
|
||
<h1 id="examples-15" class="section-header"><a href="#examples-15">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">io</span>::{<span class="self">self</span>, <span class="ident">Read</span>};
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">buffer</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">0</span>; <span class="number">3</span>];
|
||
<span class="ident">io</span>::<span class="ident">repeat</span>(<span class="number">0b101</span>).<span class="ident">read_exact</span>(<span class="ident">buffer</span>.<span class="ident">as_mut_slice</span>()).<span class="ident">unwrap</span>();</pre></div>
|
||
</div><h4 id='method.as_ptr' class="method"><code id='as_ptr.v'>pub fn <a href='#method.as_ptr' class='fnname'>as_ptr</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.pointer.html">*const T</a></code><span class='since' title='Stable since Rust version 1.37.0'>1.37.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#808-816' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns a raw pointer to the vector's buffer.</p>
|
||
<p>The caller must ensure that the vector outlives the pointer this
|
||
function returns, or else it will end up pointing to garbage.
|
||
Modifying the vector may cause its buffer to be reallocated,
|
||
which would also make any pointers to it invalid.</p>
|
||
<p>The caller must also ensure that the memory the pointer (non-transitively) points to
|
||
is never written to (except inside an <code>UnsafeCell</code>) using this pointer or any pointer
|
||
derived from it. If you need to mutate the contents of the slice, use <a href="#method.as_mut_ptr"><code>as_mut_ptr</code></a>.</p>
|
||
<h1 id="examples-16" class="section-header"><a href="#examples-16">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</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="macro">!</span>(<span class="kw-2">*</span><span class="ident">x_ptr</span>.<span class="ident">add</span>(<span class="ident">i</span>), <span class="number">1</span> <span class="op"><</span><span class="op"><</span> <span class="ident">i</span>);
|
||
}
|
||
}</pre></div>
|
||
</div><h4 id='method.as_mut_ptr' class="method"><code id='as_mut_ptr.v'>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/nightly/std/primitive.pointer.html">*mut T</a></code><span class='since' title='Stable since Rust version 1.37.0'>1.37.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#844-852' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns an unsafe mutable pointer to the vector's buffer.</p>
|
||
<p>The caller must ensure that the vector outlives the pointer this
|
||
function returns, or else it will end up pointing to garbage.
|
||
Modifying the vector may cause its buffer to be reallocated,
|
||
which would also make any pointers to it invalid.</p>
|
||
<h1 id="examples-17" class="section-header"><a href="#examples-17">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="comment">// Allocate vector big enough for 4 elements.</span>
|
||
<span class="kw">let</span> <span class="ident">size</span> <span class="op">=</span> <span class="number">4</span>;
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">x</span>: <span class="ident">Vec</span><span class="op"><</span><span class="ident">i32</span><span class="op">></span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">with_capacity</span>(<span class="ident">size</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="comment">// Initialize elements via raw pointer writes, then set length.</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">size</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="ident">i</span> <span class="kw">as</span> <span class="ident">i32</span>;
|
||
}
|
||
<span class="ident">x</span>.<span class="ident">set_len</span>(<span class="ident">size</span>);
|
||
}
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">&</span><span class="kw-2">*</span><span class="ident">x</span>, <span class="kw-2">&</span>[<span class="number">0</span>,<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]);</pre></div>
|
||
</div><h4 id='method.set_len' class="method"><code id='set_len.v'>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/nightly/std/primitive.usize.html">usize</a>)</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#934-938' title='goto source code'>[src]</a></h4><div class='docblock'><p>Forces the length of the vector to <code>new_len</code>.</p>
|
||
<p>This is a low-level operation that maintains none of the normal
|
||
invariants of the type. Normally changing the length of a vector
|
||
is done using one of the safe operations instead, such as
|
||
<a href="#method.truncate"><code>truncate</code></a>, <a href="#method.resize"><code>resize</code></a>, <a href="../../std/iter/trait.Extend.html#tymethod.extend"><code>extend</code></a>, or <a href="#method.clear"><code>clear</code></a>.</p>
|
||
<h1 id="safety-1" class="section-header"><a href="#safety-1">Safety</a></h1>
|
||
<ul>
|
||
<li><code>new_len</code> must be less than or equal to <a href="#method.capacity"><code>capacity()</code></a>.</li>
|
||
<li>The elements at <code>old_len..new_len</code> must be initialized.</li>
|
||
</ul>
|
||
<h1 id="examples-18" class="section-header"><a href="#examples-18">Examples</a></h1>
|
||
<p>This method can be useful for situations in which the vector
|
||
is serving as a buffer for other code, particularly over FFI:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">get_dictionary</span>(<span class="kw-2">&</span><span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="prelude-ty">Option</span><span class="op"><</span><span class="ident">Vec</span><span class="op"><</span><span class="ident">u8</span><span class="op">></span><span class="op">></span> {
|
||
<span class="comment">// Per the FFI method's docs, "32768 bytes is always enough".</span>
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">dict</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">with_capacity</span>(<span class="number">32_768</span>);
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">dict_length</span> <span class="op">=</span> <span class="number">0</span>;
|
||
<span class="comment">// SAFETY: When `deflateGetDictionary` returns `Z_OK`, it holds that:</span>
|
||
<span class="comment">// 1. `dict_length` elements were initialized.</span>
|
||
<span class="comment">// 2. `dict_length` <= the capacity (32_768)</span>
|
||
<span class="comment">// which makes `set_len` safe to call.</span>
|
||
<span class="kw">unsafe</span> {
|
||
<span class="comment">// Make the FFI call...</span>
|
||
<span class="kw">let</span> <span class="ident">r</span> <span class="op">=</span> <span class="ident">deflateGetDictionary</span>(<span class="self">self</span>.<span class="ident">strm</span>, <span class="ident">dict</span>.<span class="ident">as_mut_ptr</span>(), <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">dict_length</span>);
|
||
<span class="kw">if</span> <span class="ident">r</span> <span class="op">=</span><span class="op">=</span> <span class="ident">Z_OK</span> {
|
||
<span class="comment">// ...and update the length to what was initialized.</span>
|
||
<span class="ident">dict</span>.<span class="ident">set_len</span>(<span class="ident">dict_length</span>);
|
||
<span class="prelude-val">Some</span>(<span class="ident">dict</span>)
|
||
} <span class="kw">else</span> {
|
||
<span class="prelude-val">None</span>
|
||
}
|
||
}
|
||
}</pre></div>
|
||
<p>While the following example is sound, there is a memory leak since
|
||
the inner vectors were not freed prior to the <code>set_len</code> call:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>],
|
||
<span class="macro">vec</span><span class="macro">!</span>[<span class="number">0</span>, <span class="number">1</span>, <span class="number">0</span>],
|
||
<span class="macro">vec</span><span class="macro">!</span>[<span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>]];
|
||
<span class="comment">// SAFETY:</span>
|
||
<span class="comment">// 1. `old_len..0` is empty so no elements need to be initialized.</span>
|
||
<span class="comment">// 2. `0 <= capacity` always holds whatever `capacity` is.</span>
|
||
<span class="kw">unsafe</span> {
|
||
<span class="ident">vec</span>.<span class="ident">set_len</span>(<span class="number">0</span>);
|
||
}</pre></div>
|
||
<p>Normally, here, one would use <a href="#method.clear"><code>clear</code></a> instead to correctly drop
|
||
the contents and thus not leak memory.</p>
|
||
</div><h4 id='method.swap_remove' class="method"><code id='swap_remove.v'>pub fn <a href='#method.swap_remove' class='fnname'>swap_remove</a>(&mut self, index: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> T</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#963-973' title='goto source code'>[src]</a></h4><div class='docblock'><p>Removes an element from the vector and returns it.</p>
|
||
<p>The removed element is replaced by the last element of the vector.</p>
|
||
<p>This does not preserve ordering, but is O(1).</p>
|
||
<h1 id="panics-3" class="section-header"><a href="#panics-3">Panics</a></h1>
|
||
<p>Panics if <code>index</code> is out of bounds.</p>
|
||
<h1 id="examples-19" class="section-header"><a href="#examples-19">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="string">"foo"</span>, <span class="string">"bar"</span>, <span class="string">"baz"</span>, <span class="string">"qux"</span>];
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>.<span class="ident">swap_remove</span>(<span class="number">1</span>), <span class="string">"bar"</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">"foo"</span>, <span class="string">"qux"</span>, <span class="string">"baz"</span>]);
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>.<span class="ident">swap_remove</span>(<span class="number">0</span>), <span class="string">"foo"</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="string">"baz"</span>, <span class="string">"qux"</span>]);</pre></div>
|
||
</div><h4 id='method.insert' class="method"><code id='insert.v'>pub fn <a href='#method.insert' class='fnname'>insert</a>(&mut self, index: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, element: T)</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#992-1015' title='goto source code'>[src]</a></h4><div class='docblock'><p>Inserts an element at position <code>index</code> within the vector, shifting all
|
||
elements after it to the right.</p>
|
||
<h1 id="panics-4" class="section-header"><a href="#panics-4">Panics</a></h1>
|
||
<p>Panics if <code>index > len</code>.</p>
|
||
<h1 id="examples-20" class="section-header"><a href="#examples-20">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
<span class="ident">vec</span>.<span class="ident">insert</span>(<span class="number">1</span>, <span class="number">4</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>, [<span class="number">1</span>, <span class="number">4</span>, <span class="number">2</span>, <span class="number">3</span>]);
|
||
<span class="ident">vec</span>.<span class="ident">insert</span>(<span class="number">4</span>, <span class="number">5</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>, [<span class="number">1</span>, <span class="number">4</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">5</span>]);</pre></div>
|
||
</div><h4 id='method.remove' class="method"><code id='remove.v'>pub fn <a href='#method.remove' class='fnname'>remove</a>(&mut self, index: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> T</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1032-1051' title='goto source code'>[src]</a></h4><div class='docblock'><p>Removes and returns the element at position <code>index</code> within the vector,
|
||
shifting all elements after it to the left.</p>
|
||
<h1 id="panics-5" class="section-header"><a href="#panics-5">Panics</a></h1>
|
||
<p>Panics if <code>index</code> is out of bounds.</p>
|
||
<h1 id="examples-21" class="section-header"><a href="#examples-21">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>.<span class="ident">remove</span>(<span class="number">1</span>), <span class="number">2</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, [<span class="number">1</span>, <span class="number">3</span>]);</pre></div>
|
||
</div><h4 id='method.retain' class="method"><code id='retain.v'>pub fn <a href='#method.retain' class='fnname'>retain</a><F>(&mut self, f: F) <span class="where fmt-newline">where<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1077-1097' title='goto source code'>[src]</a></h4><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, visiting each element exactly once in the
|
||
original order, and preserves the order of the retained elements.</p>
|
||
<h1 id="examples-22" class="section-header"><a href="#examples-22">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>];
|
||
<span class="ident">vec</span>.<span class="ident">retain</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">2</span> <span class="op">=</span><span class="op">=</span> <span class="number">0</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>, [<span class="number">2</span>, <span class="number">4</span>]);</pre></div>
|
||
<p>The exact order may be useful for tracking external state, like an index.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</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">keep</span> <span class="op">=</span> [<span class="bool-val">false</span>, <span class="bool-val">true</span>, <span class="bool-val">true</span>, <span class="bool-val">false</span>, <span class="bool-val">true</span>];
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">i</span> <span class="op">=</span> <span class="number">0</span>;
|
||
<span class="ident">vec</span>.<span class="ident">retain</span>(<span class="op">|</span><span class="kw">_</span><span class="op">|</span> (<span class="ident">keep</span>[<span class="ident">i</span>], <span class="ident">i</span> <span class="op">+</span><span class="op">=</span> <span class="number">1</span>).<span class="number">0</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>, [<span class="number">2</span>, <span class="number">3</span>, <span class="number">5</span>]);</pre></div>
|
||
</div><h4 id='method.dedup_by_key' class="method"><code id='dedup_by_key.v'>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="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T) -> K,<br> K: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><K>, </span></code><span class='since' title='Stable since Rust version 1.16.0'>1.16.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1115-1121' title='goto source code'>[src]</a></h4><div class='docblock'><p>Removes all but the first of consecutive elements in the vector that resolve to the same
|
||
key.</p>
|
||
<p>If the vector is sorted, this removes all duplicates.</p>
|
||
<h1 id="examples-23" class="section-header"><a href="#examples-23">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">10</span>, <span class="number">20</span>, <span class="number">21</span>, <span class="number">30</span>, <span class="number">20</span>];
|
||
|
||
<span class="ident">vec</span>.<span class="ident">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="macro">!</span>(<span class="ident">vec</span>, [<span class="number">10</span>, <span class="number">20</span>, <span class="number">30</span>, <span class="number">20</span>]);</pre></div>
|
||
</div><h4 id='method.dedup_by' class="method"><code id='dedup_by.v'>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="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, </span></code><span class='since' title='Stable since Rust version 1.16.0'>1.16.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1142-1151' title='goto source code'>[src]</a></h4><div class='docblock'><p>Removes all but the first of consecutive elements in the vector satisfying a given equality
|
||
relation.</p>
|
||
<p>The <code>same_bucket</code> function is passed references to two elements from the vector 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 removed.</p>
|
||
<p>If the vector is sorted, this removes all duplicates.</p>
|
||
<h1 id="examples-24" class="section-header"><a href="#examples-24">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="string">"foo"</span>, <span class="string">"bar"</span>, <span class="string">"Bar"</span>, <span class="string">"baz"</span>, <span class="string">"bar"</span>];
|
||
|
||
<span class="ident">vec</span>.<span class="ident">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="macro">!</span>(<span class="ident">vec</span>, [<span class="string">"foo"</span>, <span class="string">"bar"</span>, <span class="string">"baz"</span>, <span class="string">"bar"</span>]);</pre></div>
|
||
</div><h4 id='method.push' class="method"><code id='push.v'>pub fn <a href='#method.push' class='fnname'>push</a>(&mut self, value: T)</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1168-1179' title='goto source code'>[src]</a></h4><div class='docblock'><p>Appends an element to the back of a collection.</p>
|
||
<h1 id="panics-6" class="section-header"><a href="#panics-6">Panics</a></h1>
|
||
<p>Panics if the number of elements in the vector overflows a <code>usize</code>.</p>
|
||
<h1 id="examples-25" class="section-header"><a href="#examples-25">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>];
|
||
<span class="ident">vec</span>.<span class="ident">push</span>(<span class="number">3</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]);</pre></div>
|
||
</div><h4 id='method.pop' class="method"><code id='pop.v'>pub fn <a href='#method.pop' class='fnname'>pop</a>(&mut self) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Option.html" title="enum nom::lib::std::prelude::v1::v1::Option">Option</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1195-1204' title='goto source code'>[src]</a></h4><div class='docblock'><p>Removes the last element from a vector and returns it, or <a href="../../std/option/enum.Option.html#variant.None"><code>None</code></a> if it
|
||
is empty.</p>
|
||
<h1 id="examples-26" class="section-header"><a href="#examples-26">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>.<span class="ident">pop</span>(), <span class="prelude-val">Some</span>(<span class="number">3</span>));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>, [<span class="number">1</span>, <span class="number">2</span>]);</pre></div>
|
||
</div><h4 id='method.append' class="method"><code id='append.v'>pub fn <a href='#method.append' class='fnname'>append</a>(&mut self, other: &mut <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>)</code><span class='since' title='Stable since Rust version 1.4.0'>1.4.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1223-1228' title='goto source code'>[src]</a></h4><div class='docblock'><p>Moves all the elements of <code>other</code> into <code>Self</code>, leaving <code>other</code> empty.</p>
|
||
<h1 id="panics-7" class="section-header"><a href="#panics-7">Panics</a></h1>
|
||
<p>Panics if the number of elements in the vector overflows a <code>usize</code>.</p>
|
||
<h1 id="examples-27" class="section-header"><a href="#examples-27">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</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">vec2</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>];
|
||
<span class="ident">vec</span>.<span class="ident">append</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">vec2</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">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="number">6</span>]);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec2</span>, []);</pre></div>
|
||
</div><h4 id='method.drain' class="method"><code id='drain.v'>pub fn <a href='#method.drain' class='fnname'>drain</a><R>(&mut self, range: R) -> <a class="struct" href="../../../../nom/lib/std/vec/struct.Drain.html" title="struct nom::lib::std::vec::Drain">Drain</a><T> <span class="where fmt-newline">where<br> R: <a class="trait" href="../../../../nom/lib/std/ops/trait.RangeBounds.html" title="trait nom::lib::std::ops::RangeBounds">RangeBounds</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>>, </span></code><span class='since' title='Stable since Rust version 1.6.0'>1.6.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1267-1308' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="panics-8" class="section-header"><a href="#panics-8">Panics</a></h1>
|
||
<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>
|
||
<h1 id="examples-28" class="section-header"><a href="#examples-28">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
<span class="kw">let</span> <span class="ident">u</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">v</span>.<span class="ident">drain</span>(<span class="number">1</span>..).<span class="ident">collect</span>();
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, <span class="kw-2">&</span>[<span class="number">1</span>]);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">u</span>, <span class="kw-2">&</span>[<span class="number">2</span>, <span class="number">3</span>]);
|
||
|
||
<span class="comment">// A full range clears the vector</span>
|
||
<span class="ident">v</span>.<span class="ident">drain</span>(..);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, <span class="kw-2">&</span>[]);</pre></div>
|
||
</div><h4 id='method.clear' class="method"><code id='clear.v'>pub fn <a href='#method.clear' class='fnname'>clear</a>(&mut self)</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1326-1328' title='goto source code'>[src]</a></h4><div class='docblock'><p>Clears the vector, removing all values.</p>
|
||
<p>Note that this method has no effect on the allocated capacity
|
||
of the vector.</p>
|
||
<h1 id="examples-29" class="section-header"><a href="#examples-29">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
|
||
<span class="ident">v</span>.<span class="ident">clear</span>();
|
||
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">v</span>.<span class="ident">is_empty</span>());</pre></div>
|
||
</div><h4 id='method.len' class="method"><code id='len.v'>pub fn <a href='#method.len' class='fnname'>len</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1341-1343' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns the number of elements in the vector, also referred to
|
||
as its 'length'.</p>
|
||
<h1 id="examples-30" class="section-header"><a href="#examples-30">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">len</span>(), <span class="number">3</span>);</pre></div>
|
||
</div><h4 id='method.is_empty' class="method"><code id='is_empty.v'>pub fn <a href='#method.is_empty' class='fnname'>is_empty</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1357-1359' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns <code>true</code> if the vector contains no elements.</p>
|
||
<h1 id="examples-31" class="section-header"><a href="#examples-31">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">new</span>();
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">v</span>.<span class="ident">is_empty</span>());
|
||
|
||
<span class="ident">v</span>.<span class="ident">push</span>(<span class="number">1</span>);
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">v</span>.<span class="ident">is_empty</span>());</pre></div>
|
||
</div><h4 id='method.split_off' class="method"><code id='split_off.v'>pub fn <a href='#method.split_off' class='fnname'>split_off</a>(&mut self, at: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><span class='since' title='Stable since Rust version 1.4.0'>1.4.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1381-1395' title='goto source code'>[src]</a></h4><div class='docblock'><p>Splits the collection into two at the given index.</p>
|
||
<p>Returns a newly allocated vector containing the elements in the range
|
||
<code>[at, len)</code>. After the call, the original vector will be left containing
|
||
the elements <code>[0, at)</code> with its previous capacity unchanged.</p>
|
||
<h1 id="panics-9" class="section-header"><a href="#panics-9">Panics</a></h1>
|
||
<p>Panics if <code>at > len</code>.</p>
|
||
<h1 id="examples-32" class="section-header"><a href="#examples-32">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>];
|
||
<span class="kw">let</span> <span class="ident">vec2</span> <span class="op">=</span> <span class="ident">vec</span>.<span class="ident">split_off</span>(<span class="number">1</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>, [<span class="number">1</span>]);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec2</span>, [<span class="number">2</span>, <span class="number">3</span>]);</pre></div>
|
||
</div><h4 id='method.resize_with' class="method"><code id='resize_with.v'>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/nightly/std/primitive.usize.html">usize</a>, f: F) <span class="where fmt-newline">where<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>() -> T, </span></code><span class='since' title='Stable since Rust version 1.33.0'>1.33.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1427-1437' title='goto source code'>[src]</a></h4><div class='docblock'><p>Resizes the <code>Vec</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>Vec</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> will end up
|
||
in the <code>Vec</code> in the order they have been generated.</p>
|
||
<p>If <code>new_len</code> is less than <code>len</code>, the <code>Vec</code> is simply truncated.</p>
|
||
<p>This method uses a closure to create new values on every push. If
|
||
you'd rather <a href="../../std/clone/trait.Clone.html"><code>Clone</code></a> a given value, use <a href="#method.resize"><code>resize</code></a>. 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>
|
||
<h1 id="examples-33" class="section-header"><a href="#examples-33">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</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</span>::<span class="ident">default</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</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="op">=</span> <span class="macro">vec</span><span class="macro">!</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="macro">!</span>(<span class="ident">vec</span>, [<span class="number">2</span>, <span class="number">4</span>, <span class="number">8</span>, <span class="number">16</span>]);</pre></div>
|
||
</div><h4 id='method.leak' class="method"><code id='leak.v'>pub fn <a href='#method.leak' class='fnname'>leak</a><'a>(vec: <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&'a mut [T]</a> <span class="where fmt-newline">where<br> T: 'a, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1464-1469' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>vec_leak</code>)</div></div><div class='docblock'><p>Consumes and leaks the <code>Vec</code>, returning a mutable reference to the contents,
|
||
<code>&'a mut [T]</code>. Note that the type <code>T</code> must outlive the chosen lifetime
|
||
<code>'a</code>. If the type has only static references, or none at all, then this
|
||
may be chosen to be <code>'static</code>.</p>
|
||
<p>This function is similar to the <code>leak</code> function on <code>Box</code>.</p>
|
||
<p>This function is mainly useful for data that lives for the remainder of
|
||
the program's life. Dropping the returned reference will cause a memory
|
||
leak.</p>
|
||
<h1 id="examples-34" class="section-header"><a href="#examples-34">Examples</a></h1>
|
||
<p>Simple usage:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="attribute">#![<span class="ident">feature</span>(<span class="ident">vec_leak</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
<span class="kw">let</span> <span class="ident">static_ref</span>: <span class="kw-2">&</span><span class="lifetime">'static</span> <span class="kw-2">mut</span> [<span class="ident">usize</span>] <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">leak</span>(<span class="ident">x</span>);
|
||
<span class="ident">static_ref</span>[<span class="number">0</span>] <span class="op">+</span><span class="op">=</span> <span class="number">1</span>;
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">static_ref</span>, <span class="kw-2">&</span>[<span class="number">2</span>, <span class="number">2</span>, <span class="number">3</span>]);</pre></div>
|
||
</div></div><h3 id='impl-1' class='impl'><code class='in-band'>impl<T> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Clone.html" title="trait nom::lib::std::prelude::v1::v1::Clone">Clone</a>, </span></code><a href='#impl-1' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1472-1533' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.resize' class="method"><code id='resize.v'>pub fn <a href='#method.resize' class='fnname'>resize</a>(&mut self, new_len: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, value: T)</code><span class='since' title='Stable since Rust version 1.5.0'>1.5.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1500-1508' title='goto source code'>[src]</a></h4><div class='docblock'><p>Resizes the <code>Vec</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>Vec</code> is extended by the
|
||
difference, with each additional slot filled with <code>value</code>.
|
||
If <code>new_len</code> is less than <code>len</code>, the <code>Vec</code> is simply truncated.</p>
|
||
<p>This method requires <code>T</code> to implement <a href="../../std/clone/trait.Clone.html"><code>Clone</code></a>,
|
||
in order to be able to clone the passed value.
|
||
If you need more flexibility (or want to rely on <a href="../../std/default/trait.Default.html"><code>Default</code></a> instead of
|
||
<a href="../../std/clone/trait.Clone.html"><code>Clone</code></a>), use <a href="#method.resize_with"><code>resize_with</code></a>.</p>
|
||
<h1 id="examples-35" class="section-header"><a href="#examples-35">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="string">"hello"</span>];
|
||
<span class="ident">vec</span>.<span class="ident">resize</span>(<span class="number">3</span>, <span class="string">"world"</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>, [<span class="string">"hello"</span>, <span class="string">"world"</span>, <span class="string">"world"</span>]);
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>];
|
||
<span class="ident">vec</span>.<span class="ident">resize</span>(<span class="number">2</span>, <span class="number">0</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>, [<span class="number">1</span>, <span class="number">2</span>]);</pre></div>
|
||
</div><h4 id='method.extend_from_slice' class="method"><code id='extend_from_slice.v'>pub fn <a href='#method.extend_from_slice' class='fnname'>extend_from_slice</a>(&mut self, other: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[T]</a>)</code><span class='since' title='Stable since Rust version 1.6.0'>1.6.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1530-1532' title='goto source code'>[src]</a></h4><div class='docblock'><p>Clones and appends all elements in a slice to the <code>Vec</code>.</p>
|
||
<p>Iterates over the slice <code>other</code>, clones each element, and then appends
|
||
it to this <code>Vec</code>. The <code>other</code> vector is traversed in-order.</p>
|
||
<p>Note that this function is same as <a href="#method.extend"><code>extend</code></a> except that it is
|
||
specialized to work with slices instead. If and when Rust gets
|
||
specialization this function will likely be deprecated (but still
|
||
available).</p>
|
||
<h1 id="examples-36" class="section-header"><a href="#examples-36">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>];
|
||
<span class="ident">vec</span>.<span class="ident">extend_from_slice</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="macro">!</span>(<span class="ident">vec</span>, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>]);</pre></div>
|
||
</div></div><h3 id='impl-2' class='impl'><code class='in-band'>impl<T> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Default.html" title="trait nom::lib::std::prelude::v1::v1::Default">Default</a>, </span></code><a href='#impl-2' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1535-1580' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.resize_default' class="method"><code id='resize_default.v'>pub fn <a href='#method.resize_default' class='fnname'>resize_default</a>(&mut self, new_len: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>)</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1571-1579' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab deprecated'>Deprecated since 1.33.0: <p>This is moving towards being removed in favor of <code>.resize_with(Default::default)</code>. If you disagree, please comment in the tracking issue.</p>
|
||
</div><div class='stab unstable'><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>vec_resize_default</code>)</div></div><div class='docblock'><p>Resizes the <code>Vec</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>Vec</code> is extended by the
|
||
difference, with each additional slot filled with <a href="../../std/default/trait.Default.html#tymethod.default"><code>Default::default()</code></a>.
|
||
If <code>new_len</code> is less than <code>len</code>, the <code>Vec</code> is simply truncated.</p>
|
||
<p>This method uses <a href="../../std/default/trait.Default.html"><code>Default</code></a> to create new values on every push. If
|
||
you'd rather <a href="../../std/clone/trait.Clone.html"><code>Clone</code></a> a given value, use <a href="#method.resize"><code>resize</code></a>.</p>
|
||
<h1 id="examples-37" class="section-header"><a href="#examples-37">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="attribute">#![<span class="ident">feature</span>(<span class="ident">vec_resize_default</span>)]</span>
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</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_default</span>(<span class="number">5</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</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="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>];
|
||
<span class="ident">vec</span>.<span class="ident">resize_default</span>(<span class="number">2</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>, [<span class="number">1</span>, <span class="number">2</span>]);</pre></div>
|
||
</div></div><h3 id='impl-3' class='impl'><code class='in-band'>impl<T> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><T>, </span></code><a href='#impl-3' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1678-1698' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.dedup' class="method"><code id='dedup.v'>pub fn <a href='#method.dedup' class='fnname'>dedup</a>(&mut self)</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1695-1697' title='goto source code'>[src]</a></h4><div class='docblock'><p>Removes consecutive repeated elements in the vector according to the
|
||
[<code>PartialEq</code>] trait implementation.</p>
|
||
<p>If the vector is sorted, this removes all duplicates.</p>
|
||
<h1 id="examples-38" class="section-header"><a href="#examples-38">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">2</span>];
|
||
|
||
<span class="ident">vec</span>.<span class="ident">dedup</span>();
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">2</span>]);</pre></div>
|
||
</div></div><h3 id='impl-4' class='impl'><code class='in-band'>impl<T> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl-4' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1700-1721' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.remove_item' class="method"><code id='remove_item.v'>pub fn <a href='#method.remove_item' class='fnname'>remove_item</a><V>(&mut self, item: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>V) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Option.html" title="enum nom::lib::std::prelude::v1::v1::Option">Option</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><V>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1714-1720' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><details><summary><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>vec_remove_item</code>)</summary><p>recently added</p>
|
||
</details></div></div><div class='docblock'><p>Removes the first instance of <code>item</code> from the vector if the item exists.</p>
|
||
<h1 id="examples-39" class="section-header"><a href="#examples-39">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vec</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">1</span>];
|
||
|
||
<span class="ident">vec</span>.<span class="ident">remove_item</span>(<span class="kw-2">&</span><span class="number">1</span>);
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>, <span class="macro">vec</span><span class="macro">!</span>[<span class="number">2</span>, <span class="number">3</span>, <span class="number">1</span>]);</pre></div>
|
||
</div></div><h3 id='impl-5' class='impl'><code class='in-band'>impl<T> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl-5' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2129-2254' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.splice' class="method"><code id='splice.v'>pub fn <a href='#method.splice' class='fnname'>splice</a><R, I>(<br> &mut self, <br> range: R, <br> replace_with: I<br>) -> <a class="struct" href="../../../../nom/lib/std/vec/struct.Splice.html" title="struct nom::lib::std::vec::Splice">Splice</a><<I as <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html" title="trait nom::lib::std::prelude::v1::v1::IntoIterator">IntoIterator</a>>::<a class="type" href="../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html#associatedtype.IntoIter" title="type nom::lib::std::prelude::v1::v1::IntoIterator::IntoIter">IntoIter</a>> <span class="where fmt-newline">where<br> I: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html" title="trait nom::lib::std::prelude::v1::v1::IntoIterator">IntoIterator</a><Item = T>,<br> R: <a class="trait" href="../../../../nom/lib/std/ops/trait.RangeBounds.html" title="trait nom::lib::std::ops::RangeBounds">RangeBounds</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>>, </span></code><span class='since' title='Stable since Rust version 1.21.0'>1.21.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2187-2193' title='goto source code'>[src]</a></h4><div class='docblock'><p>Creates a splicing iterator that replaces the specified range in the vector
|
||
with the given <code>replace_with</code> iterator and yields the removed items.
|
||
<code>replace_with</code> does not need to be the same length as <code>range</code>.</p>
|
||
<p>The element range is removed even if the iterator is not consumed until the end.</p>
|
||
<p>It is unspecified how many elements are removed from the vector
|
||
if the <code>Splice</code> value is leaked.</p>
|
||
<p>The input iterator <code>replace_with</code> is only consumed when the <code>Splice</code> value is dropped.</p>
|
||
<p>This is optimal if:</p>
|
||
<ul>
|
||
<li>The tail (elements in the vector after <code>range</code>) is empty,</li>
|
||
<li>or <code>replace_with</code> yields fewer elements than <code>range</code>’s length</li>
|
||
<li>or the lower bound of its <code>size_hint()</code> is exact.</li>
|
||
</ul>
|
||
<p>Otherwise, a temporary vector is allocated and the tail is moved twice.</p>
|
||
<h1 id="panics-10" class="section-header"><a href="#panics-10">Panics</a></h1>
|
||
<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>
|
||
<h1 id="examples-40" class="section-header"><a href="#examples-40">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
<span class="kw">let</span> <span class="ident">new</span> <span class="op">=</span> [<span class="number">7</span>, <span class="number">8</span>];
|
||
<span class="kw">let</span> <span class="ident">u</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">v</span>.<span class="ident">splice</span>(..<span class="number">2</span>, <span class="ident">new</span>.<span class="ident">iter</span>().<span class="ident">cloned</span>()).<span class="ident">collect</span>();
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, <span class="kw-2">&</span>[<span class="number">7</span>, <span class="number">8</span>, <span class="number">3</span>]);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">u</span>, <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">2</span>]);</pre></div>
|
||
</div><h4 id='method.drain_filter' class="method"><code id='drain_filter.v'>pub fn <a href='#method.drain_filter' class='fnname'>drain_filter</a><F>(&mut self, filter: F) -> <a class="struct" href="../../../../nom/lib/std/vec/struct.DrainFilter.html" title="struct nom::lib::std::vec::DrainFilter">DrainFilter</a><T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2241-2253' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><details><summary><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>drain_filter</code>)</summary><p>recently added</p>
|
||
</details></div></div><div class='docblock'><p>Creates an iterator which uses a closure to determine if an element should be removed.</p>
|
||
<p>If the closure returns true, then the element is removed and yielded.
|
||
If the closure returns false, the element will remain in the vector and will not be yielded
|
||
by the iterator.</p>
|
||
<p>Using this method is equivalent to the following code:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">i</span> <span class="op">=</span> <span class="number">0</span>;
|
||
<span class="kw">while</span> <span class="ident">i</span> <span class="op">!</span><span class="op">=</span> <span class="ident">vec</span>.<span class="ident">len</span>() {
|
||
<span class="kw">if</span> <span class="ident">some_predicate</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">vec</span>[<span class="ident">i</span>]) {
|
||
<span class="kw">let</span> <span class="ident">val</span> <span class="op">=</span> <span class="ident">vec</span>.<span class="ident">remove</span>(<span class="ident">i</span>);
|
||
<span class="comment">// your code here</span>
|
||
} <span class="kw">else</span> {
|
||
<span class="ident">i</span> <span class="op">+</span><span class="op">=</span> <span class="number">1</span>;
|
||
}
|
||
}
|
||
</pre></div>
|
||
<p>But <code>drain_filter</code> is easier to use. <code>drain_filter</code> is also more efficient,
|
||
because it can backshift the elements of the array in bulk.</p>
|
||
<p>Note that <code>drain_filter</code> also lets you mutate every element in the filter closure,
|
||
regardless of whether you choose to keep or remove it.</p>
|
||
<h1 id="examples-41" class="section-header"><a href="#examples-41">Examples</a></h1>
|
||
<p>Splitting an array into evens and odds, reusing the original allocation:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="attribute">#![<span class="ident">feature</span>(<span class="ident">drain_filter</span>)]</span>
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">numbers</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</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">8</span>, <span class="number">9</span>, <span class="number">11</span>, <span class="number">13</span>, <span class="number">14</span>, <span class="number">15</span>];
|
||
|
||
<span class="kw">let</span> <span class="ident">evens</span> <span class="op">=</span> <span class="ident">numbers</span>.<span class="ident">drain_filter</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="kw-2">*</span><span class="ident">x</span> <span class="op">%</span> <span class="number">2</span> <span class="op">=</span><span class="op">=</span> <span class="number">0</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="kw">let</span> <span class="ident">odds</span> <span class="op">=</span> <span class="ident">numbers</span>;
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">evens</span>, <span class="macro">vec</span><span class="macro">!</span>[<span class="number">2</span>, <span class="number">4</span>, <span class="number">6</span>, <span class="number">8</span>, <span class="number">14</span>]);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">odds</span>, <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">9</span>, <span class="number">11</span>, <span class="number">13</span>, <span class="number">15</span>]);</pre></div>
|
||
</div></div><h2 id='deref-methods' class='small-section-header'>Methods from <a class="trait" href="../../../../nom/lib/std/ops/trait.Deref.html" title="trait nom::lib::std::ops::Deref">Deref</a><Target = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>><a href='#deref-methods' class='anchor'></a></h2><div class='impl-items'><h4 id='method.len-1' class="method"><code id='len.v-1'>pub const fn <a href='#method.len-1' class='fnname'>len</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#73-75' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns the number of elements in the slice.</p>
|
||
<h1 id="examples-42" class="section-header"><a href="#examples-42">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</span>(<span class="ident">a</span>.<span class="ident">len</span>(), <span class="number">3</span>);</pre></div>
|
||
</div><h4 id='method.is_empty-1' class="method"><code id='is_empty.v-1'>pub const fn <a href='#method.is_empty-1' class='fnname'>is_empty</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#88-90' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns <code>true</code> if the slice has a length of 0.</p>
|
||
<h1 id="examples-43" class="section-header"><a href="#examples-43">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</span>(<span class="op">!</span><span class="ident">a</span>.<span class="ident">is_empty</span>());</pre></div>
|
||
</div><h4 id='method.first' class="method"><code id='first.v'>pub fn <a href='#method.first' class='fnname'>first</a>(&self) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Option.html" title="enum nom::lib::std::prelude::v1::v1::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#105-107' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns the first element of the slice, or <code>None</code> if it is empty.</p>
|
||
<h1 id="examples-44" class="section-header"><a href="#examples-44">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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="macro">!</span>(<span class="prelude-val">None</span>, <span class="ident">w</span>.<span class="ident">first</span>());</pre></div>
|
||
</div><h4 id='method.first_mut' class="method"><code id='first_mut.v'>pub fn <a href='#method.first_mut' class='fnname'>first_mut</a>(&mut self) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Option.html" title="enum nom::lib::std::prelude::v1::v1::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#123-125' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns a mutable pointer to the first element of the slice, or <code>None</code> if it is empty.</p>
|
||
<h1 id="examples-45" class="section-header"><a href="#examples-45">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="kw-2">&</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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.split_first' class="method"><code id='split_first.v'>pub fn <a href='#method.split_first' class='fnname'>split_first</a>(&self) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Option.html" title="enum nom::lib::std::prelude::v1::v1::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a>></code><span class='since' title='Stable since Rust version 1.5.0'>1.5.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#141-143' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="examples-46" class="section-header"><a href="#examples-46">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</span>(<span class="ident">first</span>, <span class="kw-2">&</span><span class="number">0</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">elements</span>, <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">2</span>]);
|
||
}</pre></div>
|
||
</div><h4 id='method.split_first_mut' class="method"><code id='split_first_mut.v'>pub fn <a href='#method.split_first_mut' class='fnname'>split_first_mut</a>(&mut self) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Option.html" title="enum nom::lib::std::prelude::v1::v1::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a>></code><span class='since' title='Stable since Rust version 1.5.0'>1.5.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#161-163' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="examples-47" class="section-header"><a href="#examples-47">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="kw-2">&</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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.split_last' class="method"><code id='split_last.v'>pub fn <a href='#method.split_last' class='fnname'>split_last</a>(&self) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Option.html" title="enum nom::lib::std::prelude::v1::v1::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a>></code><span class='since' title='Stable since Rust version 1.5.0'>1.5.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#179-181' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="examples-48" class="section-header"><a href="#examples-48">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</span>(<span class="ident">last</span>, <span class="kw-2">&</span><span class="number">2</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">elements</span>, <span class="kw-2">&</span>[<span class="number">0</span>, <span class="number">1</span>]);
|
||
}</pre></div>
|
||
</div><h4 id='method.split_last_mut' class="method"><code id='split_last_mut.v'>pub fn <a href='#method.split_last_mut' class='fnname'>split_last_mut</a>(&mut self) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Option.html" title="enum nom::lib::std::prelude::v1::v1::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a>></code><span class='since' title='Stable since Rust version 1.5.0'>1.5.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#199-201' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="examples-49" class="section-header"><a href="#examples-49">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="kw-2">&</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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.last' class="method"><code id='last.v'>pub fn <a href='#method.last' class='fnname'>last</a>(&self) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Option.html" title="enum nom::lib::std::prelude::v1::v1::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#216-218' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns the last element of the slice, or <code>None</code> if it is empty.</p>
|
||
<h1 id="examples-50" class="section-header"><a href="#examples-50">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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="macro">!</span>(<span class="prelude-val">None</span>, <span class="ident">w</span>.<span class="ident">last</span>());</pre></div>
|
||
</div><h4 id='method.last_mut' class="method"><code id='last_mut.v'>pub fn <a href='#method.last_mut' class='fnname'>last_mut</a>(&mut self) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Option.html" title="enum nom::lib::std::prelude::v1::v1::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#234-236' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns a mutable pointer to the last item in the slice.</p>
|
||
<h1 id="examples-51" class="section-header"><a href="#examples-51">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="kw-2">&</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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.get' class="method"><code id='get.v'>pub fn <a href='#method.get' class='fnname'>get</a><I>(&self, index: I) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Option.html" title="enum nom::lib::std::prelude::v1::v1::Option">Option</a><&<I as <a class="trait" href="../../../../nom/lib/std/slice/trait.SliceIndex.html" title="trait nom::lib::std::slice::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>>::<a class="type" href="../../../../nom/lib/std/slice/trait.SliceIndex.html#associatedtype.Output" title="type nom::lib::std::slice::SliceIndex::Output">Output</a>> <span class="where fmt-newline">where<br> I: <a class="trait" href="../../../../nom/lib/std/slice/trait.SliceIndex.html" title="trait nom::lib::std::slice::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#257-262' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="examples-52" class="section-header"><a href="#examples-52">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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="macro">!</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="macro">!</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="macro">!</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>));</pre></div>
|
||
</div><h4 id='method.get_mut' class="method"><code id='get_mut.v'>pub fn <a href='#method.get_mut' class='fnname'>get_mut</a><I>(<br> &mut self, <br> index: I<br>) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Option.html" title="enum nom::lib::std::prelude::v1::v1::Option">Option</a><&mut <I as <a class="trait" href="../../../../nom/lib/std/slice/trait.SliceIndex.html" title="trait nom::lib::std::slice::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>>::<a class="type" href="../../../../nom/lib/std/slice/trait.SliceIndex.html#associatedtype.Output" title="type nom::lib::std::slice::SliceIndex::Output">Output</a>> <span class="where fmt-newline">where<br> I: <a class="trait" href="../../../../nom/lib/std/slice/trait.SliceIndex.html" title="trait nom::lib::std::slice::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#281-286' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns a mutable reference to an element or subslice depending on the
|
||
type of index (see <a href="#method.get"><code>get</code></a>) or <code>None</code> if the index is out of bounds.</p>
|
||
<h1 id="examples-53" class="section-header"><a href="#examples-53">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="kw-2">&</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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.get_unchecked' class="method"><code id='get_unchecked.v'>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="../../../../nom/lib/std/slice/trait.SliceIndex.html" title="trait nom::lib::std::slice::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>>::<a class="type" href="../../../../nom/lib/std/slice/trait.SliceIndex.html#associatedtype.Output" title="type nom::lib::std::slice::SliceIndex::Output">Output</a> <span class="where fmt-newline">where<br> I: <a class="trait" href="../../../../nom/lib/std/slice/trait.SliceIndex.html" title="trait nom::lib::std::slice::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#310-315' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns a reference to an element or subslice, without doing bounds
|
||
checking.</p>
|
||
<p>This is generally not recommended, use with caution!
|
||
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.
|
||
For a safe alternative see <a href="#method.get"><code>get</code></a>.</p>
|
||
<h1 id="examples-54" class="section-header"><a href="#examples-54">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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>);
|
||
}</pre></div>
|
||
</div><h4 id='method.get_unchecked_mut' class="method"><code id='get_unchecked_mut.v'>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="../../../../nom/lib/std/slice/trait.SliceIndex.html" title="trait nom::lib::std::slice::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>>::<a class="type" href="../../../../nom/lib/std/slice/trait.SliceIndex.html#associatedtype.Output" title="type nom::lib::std::slice::SliceIndex::Output">Output</a> <span class="where fmt-newline">where<br> I: <a class="trait" href="../../../../nom/lib/std/slice/trait.SliceIndex.html" title="trait nom::lib::std::slice::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#341-346' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns a mutable reference to an element or subslice, without doing
|
||
bounds checking.</p>
|
||
<p>This is generally not recommended, use with caution!
|
||
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.
|
||
For a safe alternative see <a href="#method.get_mut"><code>get_mut</code></a>.</p>
|
||
<h1 id="examples-55" class="section-header"><a href="#examples-55">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="kw-2">&</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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.as_ptr-1' class="method"><code id='as_ptr.v-1'>pub const fn <a href='#method.as_ptr-1' class='fnname'>as_ptr</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.pointer.html">*const T</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#377-379' title='goto source code'>[src]</a></h4><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="#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>
|
||
<h1 id="examples-56" class="section-header"><a href="#examples-56">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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>));
|
||
}
|
||
}</pre></div>
|
||
</div><h4 id='method.as_mut_ptr-1' class="method"><code id='as_mut_ptr.v-1'>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/nightly/std/primitive.pointer.html">*mut T</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#404-406' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="examples-57" class="section-header"><a href="#examples-57">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="kw-2">&</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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.as_ptr_range' class="method"><code id='as_ptr_range.v'>pub fn <a href='#method.as_ptr_range' class='fnname'>as_ptr_range</a>(&self) -> <a class="struct" href="../../../../nom/lib/std/ops/struct.Range.html" title="struct nom::lib::std::ops::Range">Range</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.pointer.html">*const T</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#440-461' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>slice_ptr_range</code>)</div></div><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 size.</p>
|
||
<p>See <a href="#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">
|
||
<span class="attribute">#![<span class="ident">feature</span>(<span class="ident">slice_ptr_range</span>)]</span>
|
||
|
||
<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">*</span><span class="kw">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">*</span><span class="kw">const</span> <span class="kw">_</span>;
|
||
|
||
<span class="macro">assert</span><span class="macro">!</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="macro">!</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>));</pre></div>
|
||
</div><h4 id='method.as_mut_ptr_range' class="method"><code id='as_mut_ptr_range.v'>pub fn <a href='#method.as_mut_ptr_range' class='fnname'>as_mut_ptr_range</a>(&mut self) -> <a class="struct" href="../../../../nom/lib/std/ops/struct.Range.html" title="struct nom::lib::std::ops::Range">Range</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.pointer.html">*mut T</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#481-486' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>slice_ptr_range</code>)</div></div><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 size.</p>
|
||
<p>See <a href="#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><h4 id='method.swap' class="method"><code id='swap.v'>pub fn <a href='#method.swap' class='fnname'>swap</a>(&mut self, a: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, b: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>)</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#508-516' title='goto source code'>[src]</a></h4><div class='docblock'><p>Swaps two elements in the slice.</p>
|
||
<h1 id="arguments" class="section-header"><a href="#arguments">Arguments</a></h1>
|
||
<ul>
|
||
<li>a - The index of the first element</li>
|
||
<li>b - The index of the second element</li>
|
||
</ul>
|
||
<h1 id="panics-11" class="section-header"><a href="#panics-11">Panics</a></h1>
|
||
<p>Panics if <code>a</code> or <code>b</code> are out of bounds.</p>
|
||
<h1 id="examples-58" class="section-header"><a href="#examples-58">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="ident">v</span>.<span class="ident">swap</span>(<span class="number">1</span>, <span class="number">3</span>);
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">v</span> <span class="op">=</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>]);</pre></div>
|
||
</div><h4 id='method.reverse' class="method"><code id='reverse.v'>pub fn <a href='#method.reverse' class='fnname'>reverse</a>(&mut self)</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#529-589' title='goto source code'>[src]</a></h4><div class='docblock'><p>Reverses the order of elements in the slice, in place.</p>
|
||
<h1 id="examples-59" class="section-header"><a href="#examples-59">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</span>(<span class="ident">v</span> <span class="op">=</span><span class="op">=</span> [<span class="number">3</span>, <span class="number">2</span>, <span class="number">1</span>]);</pre></div>
|
||
</div><h4 id='method.iter' class="method"><code id='iter.v'>pub fn <a href='#method.iter' class='fnname'>iter</a>(&self) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.Iter.html" title="struct nom::lib::std::slice::Iter">Iter</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#606-619' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns an iterator over the slice.</p>
|
||
<h1 id="examples-60" class="section-header"><a href="#examples-60">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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="macro">!</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="macro">!</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="macro">!</span>(<span class="ident">iterator</span>.<span class="ident">next</span>(), <span class="prelude-val">None</span>);</pre></div>
|
||
</div><h4 id='method.iter_mut' class="method"><code id='iter_mut.v'>pub fn <a href='#method.iter_mut' class='fnname'>iter_mut</a>(&mut self) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.IterMut.html" title="struct nom::lib::std::slice::IterMut">IterMut</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#634-647' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns an iterator that allows modifying each value.</p>
|
||
<h1 id="examples-61" class="section-header"><a href="#examples-61">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="kw-2">&</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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.windows' class="method"><code id='windows.v'>pub fn <a href='#method.windows' class='fnname'>windows</a>(&self, size: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.Windows.html" title="struct nom::lib::std::slice::Windows">Windows</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#677-680' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="panics-12" class="section-header"><a href="#panics-12">Panics</a></h1>
|
||
<p>Panics if <code>size</code> is 0.</p>
|
||
<h1 id="examples-62" class="section-header"><a href="#examples-62">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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="macro">!</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="macro">!</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="macro">!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());</pre></div>
|
||
<p>If the slice is shorter than <code>size</code>:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());</pre></div>
|
||
</div><h4 id='method.chunks' class="method"><code id='chunks.v'>pub fn <a href='#method.chunks' class='fnname'>chunks</a>(&self, chunk_size: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.Chunks.html" title="struct nom::lib::std::slice::Chunks">Chunks</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#711-714' title='goto source code'>[src]</a></h4><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="#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="#method.rchunks"><code>rchunks</code></a> for the same iterator but starting at the end of the
|
||
slice.</p>
|
||
<h1 id="panics-13" class="section-header"><a href="#panics-13">Panics</a></h1>
|
||
<p>Panics if <code>chunk_size</code> is 0.</p>
|
||
<h1 id="examples-63" class="section-header"><a href="#examples-63">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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="macro">!</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="macro">!</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="macro">!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());</pre></div>
|
||
</div><h4 id='method.chunks_mut' class="method"><code id='chunks_mut.v'>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/nightly/std/primitive.usize.html">usize</a>) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.ChunksMut.html" title="struct nom::lib::std::slice::ChunksMut">ChunksMut</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#749-752' title='goto source code'>[src]</a></h4><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="#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="#method.rchunks_mut"><code>rchunks_mut</code></a> for the same iterator but starting at
|
||
the end of the slice.</p>
|
||
<h1 id="panics-14" class="section-header"><a href="#panics-14">Panics</a></h1>
|
||
<p>Panics if <code>chunk_size</code> is 0.</p>
|
||
<h1 id="examples-64" class="section-header"><a href="#examples-64">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&</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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.chunks_exact' class="method"><code id='chunks_exact.v'>pub fn <a href='#method.chunks_exact' class='fnname'>chunks_exact</a>(&self, chunk_size: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.ChunksExact.html" title="struct nom::lib::std::slice::ChunksExact">ChunksExact</a><T></code><span class='since' title='Stable since Rust version 1.31.0'>1.31.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#786-792' title='goto source code'>[src]</a></h4><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="#method.chunks"><code>chunks</code></a>.</p>
|
||
<p>See <a href="#method.chunks"><code>chunks</code></a> for a variant of this iterator that also returns the remainder as a smaller
|
||
chunk, and <a href="#method.rchunks_exact"><code>rchunks_exact</code></a> for the same iterator but starting at the end of the slice.</p>
|
||
<h1 id="panics-15" class="section-header"><a href="#panics-15">Panics</a></h1>
|
||
<p>Panics if <code>chunk_size</code> is 0.</p>
|
||
<h1 id="examples-65" class="section-header"><a href="#examples-65">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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="macro">!</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="macro">!</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="macro">!</span>(<span class="ident">iter</span>.<span class="ident">remainder</span>(), <span class="kw-2">&</span>[<span class="string">'m'</span>]);</pre></div>
|
||
</div><h4 id='method.chunks_exact_mut' class="method"><code id='chunks_exact_mut.v'>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/nightly/std/primitive.usize.html">usize</a>) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.ChunksExactMut.html" title="struct nom::lib::std::slice::ChunksExactMut">ChunksExactMut</a><T></code><span class='since' title='Stable since Rust version 1.31.0'>1.31.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#831-837' title='goto source code'>[src]</a></h4><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="#method.chunks_mut"><code>chunks_mut</code></a>.</p>
|
||
<p>See <a href="#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="#method.rchunks_exact_mut"><code>rchunks_exact_mut</code></a> for the same iterator but starting at the end of
|
||
the slice.</p>
|
||
<h1 id="panics-16" class="section-header"><a href="#panics-16">Panics</a></h1>
|
||
<p>Panics if <code>chunk_size</code> is 0.</p>
|
||
<h1 id="examples-66" class="section-header"><a href="#examples-66">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&</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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.rchunks' class="method"><code id='rchunks.v'>pub fn <a href='#method.rchunks' class='fnname'>rchunks</a>(&self, chunk_size: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.RChunks.html" title="struct nom::lib::std::slice::RChunks">RChunks</a><T></code><span class='since' title='Stable since Rust version 1.31.0'>1.31.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#868-871' title='goto source code'>[src]</a></h4><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="#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="#method.chunks"><code>chunks</code></a> for the same iterator but starting at the beginning
|
||
of the slice.</p>
|
||
<h1 id="panics-17" class="section-header"><a href="#panics-17">Panics</a></h1>
|
||
<p>Panics if <code>chunk_size</code> is 0.</p>
|
||
<h1 id="examples-67" class="section-header"><a href="#examples-67">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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="macro">!</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="macro">!</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="macro">!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());</pre></div>
|
||
</div><h4 id='method.rchunks_mut' class="method"><code id='rchunks_mut.v'>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/nightly/std/primitive.usize.html">usize</a>) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.RChunksMut.html" title="struct nom::lib::std::slice::RChunksMut">RChunksMut</a><T></code><span class='since' title='Stable since Rust version 1.31.0'>1.31.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#906-909' title='goto source code'>[src]</a></h4><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="#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="#method.chunks_mut"><code>chunks_mut</code></a> for the same iterator but starting at the
|
||
beginning of the slice.</p>
|
||
<h1 id="panics-18" class="section-header"><a href="#panics-18">Panics</a></h1>
|
||
<p>Panics if <code>chunk_size</code> is 0.</p>
|
||
<h1 id="examples-68" class="section-header"><a href="#examples-68">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&</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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.rchunks_exact' class="method"><code id='rchunks_exact.v'>pub fn <a href='#method.rchunks_exact' class='fnname'>rchunks_exact</a>(&self, chunk_size: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.RChunksExact.html" title="struct nom::lib::std::slice::RChunksExact">RChunksExact</a><T></code><span class='since' title='Stable since Rust version 1.31.0'>1.31.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#945-950' title='goto source code'>[src]</a></h4><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="#method.chunks"><code>chunks</code></a>.</p>
|
||
<p>See <a href="#method.rchunks"><code>rchunks</code></a> for a variant of this iterator that also returns the remainder as a smaller
|
||
chunk, and <a href="#method.chunks_exact"><code>chunks_exact</code></a> for the same iterator but starting at the beginning of the
|
||
slice.</p>
|
||
<h1 id="panics-19" class="section-header"><a href="#panics-19">Panics</a></h1>
|
||
<p>Panics if <code>chunk_size</code> is 0.</p>
|
||
<h1 id="examples-69" class="section-header"><a href="#examples-69">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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="macro">!</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="macro">!</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="macro">!</span>(<span class="ident">iter</span>.<span class="ident">remainder</span>(), <span class="kw-2">&</span>[<span class="string">'l'</span>]);</pre></div>
|
||
</div><h4 id='method.rchunks_exact_mut' class="method"><code id='rchunks_exact_mut.v'>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/nightly/std/primitive.usize.html">usize</a>) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.RChunksExactMut.html" title="struct nom::lib::std::slice::RChunksExactMut">RChunksExactMut</a><T></code><span class='since' title='Stable since Rust version 1.31.0'>1.31.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#990-995' title='goto source code'>[src]</a></h4><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="#method.chunks_mut"><code>chunks_mut</code></a>.</p>
|
||
<p>See <a href="#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="#method.chunks_exact_mut"><code>chunks_exact_mut</code></a> for the same iterator but starting at the beginning
|
||
of the slice.</p>
|
||
<h1 id="panics-20" class="section-header"><a href="#panics-20">Panics</a></h1>
|
||
<p>Panics if <code>chunk_size</code> is 0.</p>
|
||
<h1 id="examples-70" class="section-header"><a href="#examples-70">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="kw-2">&</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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.split_at' class="method"><code id='split_at.v'>pub fn <a href='#method.split_at' class='fnname'>split_at</a>(&self, mid: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[T]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1032-1034' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="panics-21" class="section-header"><a href="#panics-21">Panics</a></h1>
|
||
<p>Panics if <code>mid > len</code>.</p>
|
||
<h1 id="examples-71" class="section-header"><a href="#examples-71">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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</span><span class="macro">!</span>(<span class="ident">left</span> <span class="op">=</span><span class="op">=</span> []);
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">right</span> <span class="op">=</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">2</span>);
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">left</span> <span class="op">=</span><span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>]);
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">right</span> <span class="op">=</span><span class="op">=</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</span><span class="macro">!</span>(<span class="ident">left</span> <span class="op">=</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="macro">assert</span><span class="macro">!</span>(<span class="ident">right</span> <span class="op">=</span><span class="op">=</span> []);
|
||
}</pre></div>
|
||
</div><h4 id='method.split_at_mut' class="method"><code id='split_at_mut.v'>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/nightly/std/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1062-1071' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="panics-22" class="section-header"><a href="#panics-22">Panics</a></h1>
|
||
<p>Panics if <code>mid > len</code>.</p>
|
||
<h1 id="examples-72" class="section-header"><a href="#examples-72">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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">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</span><span class="macro">!</span>(<span class="ident">left</span> <span class="op">=</span><span class="op">=</span> [<span class="number">1</span>, <span class="number">0</span>]);
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">right</span> <span class="op">=</span><span class="op">=</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</span><span class="macro">!</span>(<span class="ident">v</span> <span class="op">=</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>]);</pre></div>
|
||
</div><h4 id='method.split' class="method"><code id='split.v'>pub fn <a href='#method.split' class='fnname'>split</a><F>(&self, pred: F) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.Split.html" title="struct nom::lib::std::slice::Split">Split</a><T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1115-1120' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="examples-73" class="section-header"><a href="#examples-73">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="op">=</span> <span class="number">0</span>);
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</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="macro">!</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="macro">!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());</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">
|
||
<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="op">=</span> <span class="number">0</span>);
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</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="macro">!</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="macro">!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());</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">
|
||
<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="op">=</span> <span class="number">0</span>);
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</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="macro">!</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="macro">!</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="macro">!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());</pre></div>
|
||
</div><h4 id='method.split_mut' class="method"><code id='split_mut.v'>pub fn <a href='#method.split_mut' class='fnname'>split_mut</a><F>(&mut self, pred: F) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.SplitMut.html" title="struct nom::lib::std::slice::SplitMut">SplitMut</a><T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1137-1142' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="examples-74" class="section-header"><a href="#examples-74">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.split_inclusive' class="method"><code id='split_inclusive.v'>pub fn <a href='#method.split_inclusive' class='fnname'>split_inclusive</a><F>(&self, pred: F) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/slice/struct.SplitInclusive.html" title="struct core::slice::SplitInclusive">SplitInclusive</a><T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1175-1180' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>split_inclusive</code>)</div></div><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>
|
||
<h1 id="examples-75" class="section-header"><a href="#examples-75">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="attribute">#![<span class="ident">feature</span>(<span class="ident">split_inclusive</span>)]</span>
|
||
<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="op">=</span> <span class="number">0</span>);
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</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="macro">!</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="macro">!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());</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">
|
||
<span class="attribute">#![<span class="ident">feature</span>(<span class="ident">split_inclusive</span>)]</span>
|
||
<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="op">=</span> <span class="number">0</span>);
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</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="macro">!</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="macro">!</span>(<span class="ident">iter</span>.<span class="ident">next</span>().<span class="ident">is_none</span>());</pre></div>
|
||
</div><h4 id='method.split_inclusive_mut' class="method"><code id='split_inclusive_mut.v'>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/nightly/core/slice/struct.SplitInclusiveMut.html" title="struct core::slice::SplitInclusiveMut">SplitInclusiveMut</a><T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1200-1205' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>split_inclusive</code>)</div></div><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>
|
||
<h1 id="examples-76" class="section-header"><a href="#examples-76">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="attribute">#![<span class="ident">feature</span>(<span class="ident">split_inclusive</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">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="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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.rsplit' class="method"><code id='rsplit.v'>pub fn <a href='#method.rsplit' class='fnname'>rsplit</a><F>(&self, pred: F) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.RSplit.html" title="struct nom::lib::std::slice::RSplit">RSplit</a><T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, </span></code><span class='since' title='Stable since Rust version 1.27.0'>1.27.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1236-1241' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="examples-77" class="section-header"><a href="#examples-77">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="op">=</span> <span class="number">0</span>);
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</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="macro">!</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="macro">!</span>(<span class="ident">iter</span>.<span class="ident">next</span>(), <span class="prelude-val">None</span>);</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">
|
||
<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="op">=</span> <span class="number">0</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</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="macro">!</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="macro">!</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="macro">!</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="macro">!</span>(<span class="ident">it</span>.<span class="ident">next</span>(), <span class="prelude-val">None</span>);</pre></div>
|
||
</div><h4 id='method.rsplit_mut' class="method"><code id='rsplit_mut.v'>pub fn <a href='#method.rsplit_mut' class='fnname'>rsplit_mut</a><F>(&mut self, pred: F) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.RSplitMut.html" title="struct nom::lib::std::slice::RSplitMut">RSplitMut</a><T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, </span></code><span class='since' title='Stable since Rust version 1.27.0'>1.27.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1262-1267' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="examples-78" class="section-header"><a href="#examples-78">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.splitn' class="method"><code id='splitn.v'>pub fn <a href='#method.splitn' class='fnname'>splitn</a><F>(&self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, pred: F) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.SplitN.html" title="struct nom::lib::std::slice::SplitN">SplitN</a><T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1290-1295' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="examples-79" class="section-header"><a href="#examples-79">Examples</a></h1>
|
||
<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">
|
||
<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="op">=</span> <span class="number">0</span>) {
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{:?}"</span>, <span class="ident">group</span>);
|
||
}</pre></div>
|
||
</div><h4 id='method.splitn_mut' class="method"><code id='splitn_mut.v'>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/nightly/std/primitive.usize.html">usize</a>, pred: F) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.SplitNMut.html" title="struct nom::lib::std::slice::SplitNMut">SplitNMut</a><T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1316-1321' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="examples-80" class="section-header"><a href="#examples-80">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.rsplitn' class="method"><code id='rsplitn.v'>pub fn <a href='#method.rsplitn' class='fnname'>rsplitn</a><F>(&self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, pred: F) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.RSplitN.html" title="struct nom::lib::std::slice::RSplitN">RSplitN</a><T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1345-1350' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="examples-81" class="section-header"><a href="#examples-81">Examples</a></h1>
|
||
<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">
|
||
<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="op">=</span> <span class="number">0</span>) {
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{:?}"</span>, <span class="ident">group</span>);
|
||
}</pre></div>
|
||
</div><h4 id='method.rsplitn_mut' class="method"><code id='rsplitn_mut.v'>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/nightly/std/primitive.usize.html">usize</a>, pred: F) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.RSplitNMut.html" title="struct nom::lib::std::slice::RSplitNMut">RSplitNMut</a><T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1372-1377' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="examples-82" class="section-header"><a href="#examples-82">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.contains' class="method"><code id='contains.v'>pub fn <a href='#method.contains' class='fnname'>contains</a>(&self, x: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><T>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1398-1403' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns <code>true</code> if the slice contains an element with the given value.</p>
|
||
<h1 id="examples-83" class="section-header"><a href="#examples-83">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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="macro">!</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>));</pre></div>
|
||
<p>If you do not have an <code>&T</code>, but just an <code>&U</code> such that <code>T: Borrow<U></code>
|
||
(e.g. <code>String: Borrow<str></code>), you can use <code>iter().any</code>:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> [<span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"hello"</span>), <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"world"</span>)]; <span class="comment">// slice of `String`</span>
|
||
<span class="macro">assert</span><span class="macro">!</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="op">=</span> <span class="string">"hello"</span>)); <span class="comment">// search with `&str`</span>
|
||
<span class="macro">assert</span><span class="macro">!</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="op">=</span> <span class="string">"hi"</span>));</pre></div>
|
||
</div><h4 id='method.starts_with' class="method"><code id='starts_with.v'>pub fn <a href='#method.starts_with' class='fnname'>starts_with</a>(&self, needle: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[T]</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><T>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1426-1432' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns <code>true</code> if <code>needle</code> is a prefix of the slice.</p>
|
||
<h1 id="examples-84" class="section-header"><a href="#examples-84">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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="macro">!</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="macro">!</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="macro">!</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>]));</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">
|
||
<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="macro">!</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="macro">!</span>(<span class="ident">v</span>.<span class="ident">starts_with</span>(<span class="kw-2">&</span>[]));</pre></div>
|
||
</div><h4 id='method.ends_with' class="method"><code id='ends_with.v'>pub fn <a href='#method.ends_with' class='fnname'>ends_with</a>(&self, needle: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[T]</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><T>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1455-1461' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns <code>true</code> if <code>needle</code> is a suffix of the slice.</p>
|
||
<h1 id="examples-85" class="section-header"><a href="#examples-85">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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="macro">!</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="macro">!</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="macro">!</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>]));</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">
|
||
<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="macro">!</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="macro">!</span>(<span class="ident">v</span>.<span class="ident">ends_with</span>(<span class="kw-2">&</span>[]));</pre></div>
|
||
</div><h4 id='method.binary_search' class="method"><code id='binary_search.v'>pub fn <a href='#method.binary_search' class='fnname'>binary_search</a>(&self, x: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Result.html" title="enum nom::lib::std::prelude::v1::v1::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Ord.html" title="trait nom::lib::std::prelude::v1::v1::Ord">Ord</a>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1498-1503' title='goto source code'>[src]</a></h4><div class='docblock'><p>Binary searches this sorted slice for a given element.</p>
|
||
<p>If the value is found then [<code>Result::Ok</code>] is returned, containing the
|
||
index of the matching element. If there are multiple matches, then any
|
||
one of the matches could be returned. If the value is not found then
|
||
[<code>Result::Err</code>] is returned, containing the index where a matching
|
||
element could be inserted while maintaining sorted order.</p>
|
||
<h1 id="examples-86" class="section-header"><a href="#examples-86">Examples</a></h1>
|
||
<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">
|
||
<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="macro">!</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="macro">!</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="macro">!</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="macro">!</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="op">=</span><span class="op">></span> <span class="bool-val">true</span>, <span class="kw">_</span> <span class="op">=</span><span class="op">></span> <span class="bool-val">false</span>, });</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">
|
||
<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="macro">!</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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.binary_search_by' class="method"><code id='binary_search_by.v'>pub fn <a href='#method.binary_search_by' class='fnname'>binary_search_by</a><'a, F>(&'a self, f: F) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Result.html" title="enum nom::lib::std::prelude::v1::v1::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>> <span class="where fmt-newline">where<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a </a>T) -> <a class="enum" href="../../../../nom/lib/std/cmp/enum.Ordering.html" title="enum nom::lib::std::cmp::Ordering">Ordering</a>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1539-1562' title='goto source code'>[src]</a></h4><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 [<code>Result::Ok</code>] is returned, containing the
|
||
index of the matching element. If there are multiple matches, then any
|
||
one of the matches could be returned. If the value is not found then
|
||
[<code>Result::Err</code>] is returned, containing the index where a matching
|
||
element could be inserted while maintaining sorted order.</p>
|
||
<h1 id="examples-87" class="section-header"><a href="#examples-87">Examples</a></h1>
|
||
<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">
|
||
<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="macro">!</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="macro">!</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="macro">!</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="macro">!</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="op">=</span><span class="op">></span> <span class="bool-val">true</span>, <span class="kw">_</span> <span class="op">=</span><span class="op">></span> <span class="bool-val">false</span>, });</pre></div>
|
||
</div><h4 id='method.binary_search_by_key' class="method"><code id='binary_search_by_key.v'>pub fn <a href='#method.binary_search_by_key' class='fnname'>binary_search_by_key</a><'a, B, F>(<br> &'a self, <br> b: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>B, <br> f: F<br>) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Result.html" title="enum nom::lib::std::prelude::v1::v1::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>> <span class="where fmt-newline">where<br> B: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Ord.html" title="trait nom::lib::std::prelude::v1::v1::Ord">Ord</a>,<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a </a>T) -> B, </span></code><span class='since' title='Stable since Rust version 1.10.0'>1.10.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1597-1603' title='goto source code'>[src]</a></h4><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="#method.sort_by_key"><code>sort_by_key</code></a> using the same key extraction function.</p>
|
||
<p>If the value is found then [<code>Result::Ok</code>] is returned, containing the
|
||
index of the matching element. If there are multiple matches, then any
|
||
one of the matches could be returned. If the value is not found then
|
||
[<code>Result::Err</code>] is returned, containing the index where a matching
|
||
element could be inserted while maintaining sorted order.</p>
|
||
<h1 id="examples-88" class="section-header"><a href="#examples-88">Examples</a></h1>
|
||
<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">
|
||
<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="macro">!</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="macro">!</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="macro">!</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="macro">!</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="op">=</span><span class="op">></span> <span class="bool-val">true</span>, <span class="kw">_</span> <span class="op">=</span><span class="op">></span> <span class="bool-val">false</span>, });</pre></div>
|
||
</div><h4 id='method.sort_unstable' class="method"><code id='sort_unstable.v'>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="../../../../nom/lib/std/prelude/v1/v1/trait.Ord.html" title="trait nom::lib::std::prelude::v1::v1::Ord">Ord</a>, </span></code><span class='since' title='Stable since Rust version 1.20.0'>1.20.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1633-1638' title='goto source code'>[src]</a></h4><div class='docblock'><p>Sorts the slice, but may 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 <code>O(n log n)</code> worst-case.</p>
|
||
<h1 id="current-implementation" class="section-header"><a href="#current-implementation">Current implementation</a></h1>
|
||
<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>
|
||
<h1 id="examples-89" class="section-header"><a href="#examples-89">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</span>(<span class="ident">v</span> <span class="op">=</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>]);</pre></div>
|
||
</div><h4 id='method.sort_unstable_by' class="method"><code id='sort_unstable_by.v'>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="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> <a class="enum" href="../../../../nom/lib/std/cmp/enum.Ordering.html" title="enum nom::lib::std::cmp::Ordering">Ordering</a>, </span></code><span class='since' title='Stable since Rust version 1.20.0'>1.20.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1688-1693' title='goto source code'>[src]</a></h4><div class='docblock'><p>Sorts the slice with a comparator function, but may 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 <code>O(n log n)</code> 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 a, b and c):</p>
|
||
<ul>
|
||
<li>total and antisymmetric: exactly one of a < b, a == b or a > b is true; and</li>
|
||
<li>transitive, a < b and b < c implies a < c. The same must hold for both == and >.</li>
|
||
</ul>
|
||
<p>For example, while [<code>f64</code>] doesn't implement [<code>Ord</code>] 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">
|
||
<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="macro">!</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>]);</pre></div>
|
||
<h1 id="current-implementation-1" class="section-header"><a href="#current-implementation-1">Current implementation</a></h1>
|
||
<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>
|
||
<h1 id="examples-90" class="section-header"><a href="#examples-90">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</span>(<span class="ident">v</span> <span class="op">=</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="macro">!</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">3</span>, <span class="number">2</span>, <span class="number">1</span>]);</pre></div>
|
||
</div><h4 id='method.sort_unstable_by_key' class="method"><code id='sort_unstable_by_key.v'>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="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> K,<br> K: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Ord.html" title="trait nom::lib::std::prelude::v1::v1::Ord">Ord</a>, </span></code><span class='since' title='Stable since Rust version 1.20.0'>1.20.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1726-1732' title='goto source code'>[src]</a></h4><div class='docblock'><p>Sorts the slice with a key extraction function, but may 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 <code>O(m n log(m n))</code> worst-case, where the key function is
|
||
<code>O(m)</code>.</p>
|
||
<h1 id="current-implementation-2" class="section-header"><a href="#current-implementation-2">Current implementation</a></h1>
|
||
<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>
|
||
<h1 id="examples-91" class="section-header"><a href="#examples-91">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</span>(<span class="ident">v</span> <span class="op">=</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>]);</pre></div>
|
||
</div><h4 id='method.partition_at_index' class="method"><code id='partition_at_index.v'>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/nightly/std/primitive.usize.html">usize</a><br>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Ord.html" title="trait nom::lib::std::prelude::v1::v1::Ord">Ord</a>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1774-1780' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>slice_partition_at_index</code>)</div></div><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 <code>O(n)</code> 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>
|
||
<h1 id="current-implementation-3" class="section-header"><a href="#current-implementation-3">Current implementation</a></h1>
|
||
<p>The current algorithm is based on the quickselect portion of the same quicksort algorithm
|
||
used for <a href="#method.sort_unstable"><code>sort_unstable</code></a>.</p>
|
||
<h1 id="panics-23" class="section-header"><a href="#panics-23">Panics</a></h1>
|
||
<p>Panics when <code>index >= len()</code>, meaning it always panics on empty slices.</p>
|
||
<h1 id="examples-92" class="section-header"><a href="#examples-92">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="attribute">#![<span class="ident">feature</span>(<span class="ident">slice_partition_at_index</span>)]</span>
|
||
|
||
<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">partition_at_index</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="macro">!</span>(<span class="ident">v</span> <span class="op">=</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="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="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="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>]);</pre></div>
|
||
</div><h4 id='method.partition_at_index_by' class="method"><code id='partition_at_index_by.v'>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/nightly/std/primitive.usize.html">usize</a>, <br> compare: F<br>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> <a class="enum" href="../../../../nom/lib/std/cmp/enum.Ordering.html" title="enum nom::lib::std::cmp::Ordering">Ordering</a>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1824-1834' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>slice_partition_at_index</code>)</div></div><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 <code>O(n)</code> 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>
|
||
<h1 id="current-implementation-4" class="section-header"><a href="#current-implementation-4">Current implementation</a></h1>
|
||
<p>The current algorithm is based on the quickselect portion of the same quicksort algorithm
|
||
used for <a href="#method.sort_unstable"><code>sort_unstable</code></a>.</p>
|
||
<h1 id="panics-24" class="section-header"><a href="#panics-24">Panics</a></h1>
|
||
<p>Panics when <code>index >= len()</code>, meaning it always panics on empty slices.</p>
|
||
<h1 id="examples-93" class="section-header"><a href="#examples-93">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="attribute">#![<span class="ident">feature</span>(<span class="ident">slice_partition_at_index</span>)]</span>
|
||
|
||
<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">partition_at_index_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="macro">!</span>(<span class="ident">v</span> <span class="op">=</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="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="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="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>]);</pre></div>
|
||
</div><h4 id='method.partition_at_index_by_key' class="method"><code id='partition_at_index_by_key.v'>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/nightly/std/primitive.usize.html">usize</a>, <br> f: F<br>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> K,<br> K: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Ord.html" title="trait nom::lib::std::prelude::v1::v1::Ord">Ord</a>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1878-1889' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>slice_partition_at_index</code>)</div></div><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 <code>O(n)</code> 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>
|
||
<h1 id="current-implementation-5" class="section-header"><a href="#current-implementation-5">Current implementation</a></h1>
|
||
<p>The current algorithm is based on the quickselect portion of the same quicksort algorithm
|
||
used for <a href="#method.sort_unstable"><code>sort_unstable</code></a>.</p>
|
||
<h1 id="panics-25" class="section-header"><a href="#panics-25">Panics</a></h1>
|
||
<p>Panics when <code>index >= len()</code>, meaning it always panics on empty slices.</p>
|
||
<h1 id="examples-94" class="section-header"><a href="#examples-94">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="attribute">#![<span class="ident">feature</span>(<span class="ident">slice_partition_at_index</span>)]</span>
|
||
|
||
<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">partition_at_index_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="macro">!</span>(<span class="ident">v</span> <span class="op">=</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="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="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="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>]);</pre></div>
|
||
</div><h4 id='method.partition_dedup' class="method"><code id='partition_dedup.v'>pub fn <a href='#method.partition_dedup' class='fnname'>partition_dedup</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><T>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1913-1918' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>slice_partition_dedup</code>)</div></div><div class='docblock'><p>Moves all consecutive repeated elements to the end of the slice according to the
|
||
[<code>PartialEq</code>] 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>
|
||
<h1 id="examples-95" class="section-header"><a href="#examples-95">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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="macro">!</span>(<span class="ident">duplicates</span>, [<span class="number">2</span>, <span class="number">3</span>, <span class="number">1</span>]);</pre></div>
|
||
</div><h4 id='method.partition_dedup_by' class="method"><code id='partition_dedup_by.v'>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/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#1947-2034' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>slice_partition_dedup</code>)</div></div><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>
|
||
<h1 id="examples-96" class="section-header"><a href="#examples-96">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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="macro">!</span>(<span class="ident">duplicates</span>, [<span class="string">"bar"</span>, <span class="string">"Foo"</span>, <span class="string">"BAZ"</span>]);</pre></div>
|
||
</div><h4 id='method.partition_dedup_by_key' class="method"><code id='partition_dedup_by_key.v'>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/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T) -> K,<br> K: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><K>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2058-2064' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>slice_partition_dedup</code>)</div></div><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>
|
||
<h1 id="examples-97" class="section-header"><a href="#examples-97">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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="macro">!</span>(<span class="ident">duplicates</span>, [<span class="number">21</span>, <span class="number">30</span>, <span class="number">13</span>]);</pre></div>
|
||
</div><h4 id='method.rotate_left' class="method"><code id='rotate_left.v'>pub fn <a href='#method.rotate_left' class='fnname'>rotate_left</a>(&mut self, mid: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>)</code><span class='since' title='Stable since Rust version 1.26.0'>1.26.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2097-2105' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="panics-26" class="section-header"><a href="#panics-26">Panics</a></h1>
|
||
<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>
|
||
<h1 id="complexity" class="section-header"><a href="#complexity">Complexity</a></h1>
|
||
<p>Takes linear (in <code>self.len()</code>) time.</p>
|
||
<h1 id="examples-98" class="section-header"><a href="#examples-98">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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>]);</pre></div>
|
||
<p>Rotating a subslice:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.rotate_right' class="method"><code id='rotate_right.v'>pub fn <a href='#method.rotate_right' class='fnname'>rotate_right</a>(&mut self, k: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>)</code><span class='since' title='Stable since Rust version 1.26.0'>1.26.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2138-2146' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="panics-27" class="section-header"><a href="#panics-27">Panics</a></h1>
|
||
<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>
|
||
<h1 id="complexity-1" class="section-header"><a href="#complexity-1">Complexity</a></h1>
|
||
<p>Takes linear (in <code>self.len()</code>) time.</p>
|
||
<h1 id="examples-99" class="section-header"><a href="#examples-99">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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>]);</pre></div>
|
||
<p>Rotate a subslice:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.clone_from_slice' class="method"><code id='clone_from_slice.v'>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/nightly/std/primitive.slice.html">&[T]</a>) <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Clone.html" title="trait nom::lib::std::prelude::v1::v1::Clone">Clone</a>, </span></code><span class='since' title='Stable since Rust version 1.7.0'>1.7.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2204-2217' title='goto source code'>[src]</a></h4><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>
|
||
<p>If <code>src</code> implements <code>Copy</code>, it can be more performant to use
|
||
<a href="#method.copy_from_slice"><code>copy_from_slice</code></a>.</p>
|
||
<h1 id="panics-28" class="section-header"><a href="#panics-28">Panics</a></h1>
|
||
<p>This function will panic if the two slices have different lengths.</p>
|
||
<h1 id="examples-100" class="section-header"><a href="#examples-100">Examples</a></h1>
|
||
<p>Cloning two elements from a slice into another:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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="macro">!</span>(<span class="ident">dst</span>, [<span class="number">3</span>, <span class="number">4</span>]);</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'>ⓘ<span class='tooltiptext'>This example deliberately fails to compile</span></div></div><div class="example-wrap"><pre class="rust rust-example-rendered compile_fail">
|
||
<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></pre></div>
|
||
<p>To work around this, we can use <a href="#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">
|
||
<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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.copy_from_slice' class="method"><code id='copy_from_slice.v'>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/nightly/std/primitive.slice.html">&[T]</a>) <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Copy.html" title="trait nom::lib::std::prelude::v1::v1::Copy">Copy</a>, </span></code><span class='since' title='Stable since Rust version 1.9.0'>1.9.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2274-2282' title='goto source code'>[src]</a></h4><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>src</code> does not implement <code>Copy</code>, use <a href="#method.clone_from_slice"><code>clone_from_slice</code></a>.</p>
|
||
<h1 id="panics-29" class="section-header"><a href="#panics-29">Panics</a></h1>
|
||
<p>This function will panic if the two slices have different lengths.</p>
|
||
<h1 id="examples-101" class="section-header"><a href="#examples-101">Examples</a></h1>
|
||
<p>Copying two elements from a slice into another:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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="macro">!</span>(<span class="ident">dst</span>, [<span class="number">3</span>, <span class="number">4</span>]);</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'>ⓘ<span class='tooltiptext'>This example deliberately fails to compile</span></div></div><div class="example-wrap"><pre class="rust rust-example-rendered compile_fail">
|
||
<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></pre></div>
|
||
<p>To work around this, we can use <a href="#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">
|
||
<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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.copy_within' class="method"><code id='copy_within.v'>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/nightly/std/primitive.usize.html">usize</a>) <span class="where fmt-newline">where<br> R: <a class="trait" href="../../../../nom/lib/std/ops/trait.RangeBounds.html" title="trait nom::lib::std::ops::RangeBounds">RangeBounds</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>>,<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Copy.html" title="trait nom::lib::std::prelude::v1::v1::Copy">Copy</a>, </span></code><span class='since' title='Stable since Rust version 1.37.0'>1.37.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2309-2334' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="panics-30" class="section-header"><a href="#panics-30">Panics</a></h1>
|
||
<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>
|
||
<h1 id="examples-102" class="section-header"><a href="#examples-102">Examples</a></h1>
|
||
<p>Copying four bytes within a slice:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</span>(<span class="kw-2">&</span><span class="ident">bytes</span>, <span class="string">b"Hello, Wello!"</span>);</pre></div>
|
||
</div><h4 id='method.swap_with_slice' class="method"><code id='swap_with_slice.v'>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/nightly/std/primitive.slice.html">&mut [T]</a>)</code><span class='since' title='Stable since Rust version 1.27.0'>1.27.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2384-2389' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="panics-31" class="section-header"><a href="#panics-31">Panics</a></h1>
|
||
<p>This function will panic if the two slices have different lengths.</p>
|
||
<h1 id="example" class="section-header"><a href="#example">Example</a></h1>
|
||
<p>Swapping two elements across slices:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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">&</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="macro">!</span>(<span class="ident">slice1</span>, [<span class="number">3</span>, <span class="number">4</span>]);
|
||
<span class="macro">assert_eq</span><span class="macro">!</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>]);</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'>ⓘ<span class='tooltiptext'>This example deliberately fails to compile</span></div></div><div class="example-wrap"><pre class="rust rust-example-rendered compile_fail">
|
||
<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">&</span><span class="kw-2">mut</span> <span class="ident">slice</span>[<span class="number">3</span>..]); <span class="comment">// compile fail!</span></pre></div>
|
||
<p>To work around this, we can use <a href="#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">
|
||
<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">&</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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.align_to' class="method"><code id='align_to.v'>pub unsafe fn <a href='#method.align_to' class='fnname'>align_to</a><U>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[T]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[U]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a></code><span class='since' title='Stable since Rust version 1.30.0'>1.30.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2487-2510' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="safety-2" class="section-header"><a href="#safety-2">Safety</a></h1>
|
||
<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>
|
||
<h1 id="examples-103" class="section-header"><a href="#examples-103">Examples</a></h1>
|
||
<p>Basic usage:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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>
|
||
}</pre></div>
|
||
</div><h4 id='method.align_to_mut' class="method"><code id='align_to_mut.v'>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/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [U]</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a></code><span class='since' title='Stable since Rust version 1.30.0'>1.30.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2543-2569' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="safety-3" class="section-header"><a href="#safety-3">Safety</a></h1>
|
||
<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>
|
||
<h1 id="examples-104" class="section-header"><a href="#examples-104">Examples</a></h1>
|
||
<p>Basic usage:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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>
|
||
}</pre></div>
|
||
</div><h4 id='method.is_sorted' class="method"><code id='is_sorted.v'>pub fn <a href='#method.is_sorted' class='fnname'>is_sorted</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialOrd.html" title="trait nom::lib::std::prelude::v1::v1::PartialOrd">PartialOrd</a><T>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2594-2599' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><details><summary><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>is_sorted</code>)</summary><p>new API</p>
|
||
</details></div></div><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>
|
||
<h1 id="examples-105" class="section-header"><a href="#examples-105">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</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="macro">!</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="macro">!</span>([<span class="number">0</span>].<span class="ident">is_sorted</span>());
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">empty</span>.<span class="ident">is_sorted</span>());
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span>[<span class="number">0.0</span>, <span class="number">1.0</span>, <span class="ident">std</span>::<span class="ident">f32</span>::<span class="ident">NAN</span>].<span class="ident">is_sorted</span>());</pre></div>
|
||
</div><h4 id='method.is_sorted_by' class="method"><code id='is_sorted_by.v'>pub fn <a href='#method.is_sorted_by' class='fnname'>is_sorted_by</a><F>(&self, compare: F) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Option.html" title="enum nom::lib::std::prelude::v1::v1::Option">Option</a><<a class="enum" href="../../../../nom/lib/std/cmp/enum.Ordering.html" title="enum nom::lib::std::cmp::Ordering">Ordering</a>>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2609-2614' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><details><summary><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>is_sorted</code>)</summary><p>new API</p>
|
||
</details></div></div><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="#method.is_sorted"><code>is_sorted</code></a>; see its documentation for more information.</p>
|
||
</div><h4 id='method.is_sorted_by_key' class="method"><code id='is_sorted_by_key.v'>pub fn <a href='#method.is_sorted_by_key' class='fnname'>is_sorted_by_key</a><F, K>(&self, f: F) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> K,<br> K: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialOrd.html" title="trait nom::lib::std::prelude::v1::v1::PartialOrd">PartialOrd</a><K>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2634-2640' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><details><summary><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>is_sorted</code>)</summary><p>new API</p>
|
||
</details></div></div><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="#method.is_sorted"><code>is_sorted</code></a>; see its
|
||
documentation for more information.</p>
|
||
<h1 id="examples-106" class="section-header"><a href="#examples-106">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="attribute">#![<span class="ident">feature</span>(<span class="ident">is_sorted</span>)]</span>
|
||
|
||
<span class="macro">assert</span><span class="macro">!</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="macro">!</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>()));</pre></div>
|
||
</div></div><div class='impl-items'><h4 id='method.is_ascii' class="method"><code id='is_ascii.v'>pub fn <a href='#method.is_ascii' class='fnname'>is_ascii</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><span class='since' title='Stable since Rust version 1.23.0'>1.23.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2649-2651' title='goto source code'>[src]</a></h4><div class='docblock'><p>Checks if all bytes in this slice are within the ASCII range.</p>
|
||
</div><h4 id='method.eq_ignore_ascii_case' class="method"><code id='eq_ignore_ascii_case.v'>pub fn <a href='#method.eq_ignore_ascii_case' class='fnname'>eq_ignore_ascii_case</a>(&self, other: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><span class='since' title='Stable since Rust version 1.23.0'>1.23.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2659-2661' title='goto source code'>[src]</a></h4><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><h4 id='method.make_ascii_uppercase' class="method"><code id='make_ascii_uppercase.v'>pub fn <a href='#method.make_ascii_uppercase' class='fnname'>make_ascii_uppercase</a>(&mut self)</code><span class='since' title='Stable since Rust version 1.23.0'>1.23.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2674-2678' title='goto source code'>[src]</a></h4><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><h4 id='method.make_ascii_lowercase' class="method"><code id='make_ascii_lowercase.v'>pub fn <a href='#method.make_ascii_lowercase' class='fnname'>make_ascii_lowercase</a>(&mut self)</code><span class='since' title='Stable since Rust version 1.23.0'>1.23.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/slice/mod.rs.html#2691-2695' title='goto source code'>[src]</a></h4><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></div><div class='impl-items'><h4 id='method.sort' class="method"><code id='sort.v'>pub fn <a href='#method.sort' class='fnname'>sort</a>(&mut self) <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Ord.html" title="trait nom::lib::std::prelude::v1::v1::Ord">Ord</a>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#195-200' title='goto source code'>[src]</a></h4><div class='docblock'><p>Sorts the slice.</p>
|
||
<p>This sort is stable (i.e., does not reorder equal elements) and <code>O(n log n)</code> 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="#method.sort_unstable"><code>sort_unstable</code></a>.</p>
|
||
<h1 id="current-implementation-6" class="section-header"><a href="#current-implementation-6">Current implementation</a></h1>
|
||
<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>
|
||
<h1 id="examples-107" class="section-header"><a href="#examples-107">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</span>(<span class="ident">v</span> <span class="op">=</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>]);</pre></div>
|
||
</div><h4 id='method.sort_by' class="method"><code id='sort_by.v'>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="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> <a class="enum" href="../../../../nom/lib/std/cmp/enum.Ordering.html" title="enum nom::lib::std::cmp::Ordering">Ordering</a>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#249-254' title='goto source code'>[src]</a></h4><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 <code>O(n log n)</code> 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 [<code>f64</code>] doesn't implement [<code>Ord</code>] 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">
|
||
<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="macro">!</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>]);</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="#method.sort_unstable_by"><code>sort_unstable_by</code></a>.</p>
|
||
<h1 id="current-implementation-7" class="section-header"><a href="#current-implementation-7">Current implementation</a></h1>
|
||
<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>
|
||
<h1 id="examples-108" class="section-header"><a href="#examples-108">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</span>(<span class="ident">v</span> <span class="op">=</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="macro">!</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">3</span>, <span class="number">2</span>, <span class="number">1</span>]);</pre></div>
|
||
</div><h4 id='method.sort_by_key' class="method"><code id='sort_by_key.v'>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="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> K,<br> K: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Ord.html" title="trait nom::lib::std::prelude::v1::v1::Ord">Ord</a>, </span></code><span class='since' title='Stable since Rust version 1.7.0'>1.7.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#289-295' title='goto source code'>[src]</a></h4><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 <code>O(m n log(m n))</code>
|
||
worst-case, where the key function is <code>O(m)</code>.</p>
|
||
<p>For expensive key functions (e.g. functions that are not simple property accesses or
|
||
basic operations), <a href="#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="#method.sort_unstable_by_key"><code>sort_unstable_by_key</code></a>.</p>
|
||
<h1 id="current-implementation-8" class="section-header"><a href="#current-implementation-8">Current implementation</a></h1>
|
||
<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>
|
||
<h1 id="examples-109" class="section-header"><a href="#examples-109">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</span>(<span class="ident">v</span> <span class="op">=</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>]);</pre></div>
|
||
</div><h4 id='method.sort_by_cached_key' class="method"><code id='sort_by_cached_key.v'>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="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> K,<br> K: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Ord.html" title="trait nom::lib::std::prelude::v1::v1::Ord">Ord</a>, </span></code><span class='since' title='Stable since Rust version 1.34.0'>1.34.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#331-375' title='goto source code'>[src]</a></h4><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 <code>O(m n + n log n)</code>
|
||
worst-case, where the key function is <code>O(m)</code>.</p>
|
||
<p>For simple key functions (e.g., functions that are property accesses or
|
||
basic operations), <a href="#method.sort_by_key"><code>sort_by_key</code></a> is likely to be
|
||
faster.</p>
|
||
<h1 id="current-implementation-9" class="section-header"><a href="#current-implementation-9">Current implementation</a></h1>
|
||
<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>
|
||
<h1 id="examples-110" class="section-header"><a href="#examples-110">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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="macro">!</span>(<span class="ident">v</span> <span class="op">=</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>]);</pre></div>
|
||
</div><h4 id='method.to_vec' class="method"><code id='to_vec.v'>pub fn <a href='#method.to_vec' class='fnname'>to_vec</a>(&self) -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Clone.html" title="trait nom::lib::std::prelude::v1::v1::Clone">Clone</a>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#389-395' title='goto source code'>[src]</a></h4><div class='docblock'><p>Copies <code>self</code> into a new <code>Vec</code>.</p>
|
||
<h1 id="examples-111" class="section-header"><a href="#examples-111">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<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></pre></div>
|
||
</div><h4 id='method.repeat' class="method"><code id='repeat.v'>pub fn <a href='#method.repeat' class='fnname'>repeat</a>(&self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Copy.html" title="trait nom::lib::std::prelude::v1::v1::Copy">Copy</a>, </span></code><span class='since' title='Stable since Rust version 1.40.0'>1.40.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#439-495' title='goto source code'>[src]</a></h4><div class='docblock'><p>Creates a vector by repeating a slice <code>n</code> times.</p>
|
||
<h1 id="panics-32" class="section-header"><a href="#panics-32">Panics</a></h1>
|
||
<p>This function will panic if the capacity would overflow.</p>
|
||
<h1 id="examples-112" class="section-header"><a href="#examples-112">Examples</a></h1>
|
||
<p>Basic usage:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="macro">assert_eq</span><span class="macro">!</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="macro">!</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>]);</pre></div>
|
||
<p>A panic upon overflow:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="comment">// this will panic at runtime</span>
|
||
<span class="string">b"0123456789abcdef"</span>.<span class="ident">repeat</span>(<span class="ident">usize</span>::<span class="ident">max_value</span>());</pre></div>
|
||
</div><h4 id='method.concat' class="method"><code id='concat.v'>pub fn <a href='#method.concat' class='fnname'>concat</a><Item>(&self) -> <<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a> as <a class="trait" href="../../../../nom/lib/std/slice/trait.Concat.html" title="trait nom::lib::std::slice::Concat">Concat</a><Item>>::<a class="type" href="../../../../nom/lib/std/slice/trait.Concat.html#associatedtype.Output" title="type nom::lib::std::slice::Concat::Output">Output</a> <span class="where fmt-newline">where<br> Item: ?<a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Sized.html" title="trait nom::lib::std::prelude::v1::v1::Sized">Sized</a>,<br> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>: <a class="trait" href="../../../../nom/lib/std/slice/trait.Concat.html" title="trait nom::lib::std::slice::Concat">Concat</a><Item>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#506-511' title='goto source code'>[src]</a></h4><div class='docblock'><p>Flattens a slice of <code>T</code> into a single value <code>Self::Output</code>.</p>
|
||
<h1 id="examples-113" class="section-header"><a href="#examples-113">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="macro">assert_eq</span><span class="macro">!</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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.join' class="method"><code id='join.v'>pub fn <a href='#method.join' class='fnname'>join</a><Separator>(<br> &self, <br> sep: Separator<br>) -> <<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a> as <a class="trait" href="../../../../nom/lib/std/slice/trait.Join.html" title="trait nom::lib::std::slice::Join">Join</a><Separator>>::<a class="type" href="../../../../nom/lib/std/slice/trait.Join.html#associatedtype.Output" title="type nom::lib::std::slice::Join::Output">Output</a> <span class="where fmt-newline">where<br> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>: <a class="trait" href="../../../../nom/lib/std/slice/trait.Join.html" title="trait nom::lib::std::slice::Join">Join</a><Separator>, </span></code><span class='since' title='Stable since Rust version 1.3.0'>1.3.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#524-529' title='goto source code'>[src]</a></h4><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>
|
||
<h1 id="examples-114" class="section-header"><a href="#examples-114">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="macro">assert_eq</span><span class="macro">!</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="macro">!</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="macro">!</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>]);</pre></div>
|
||
</div><h4 id='method.connect' class="method"><code id='connect.v'>pub fn <a href='#method.connect' class='fnname'>connect</a><Separator>(<br> &self, <br> sep: Separator<br>) -> <<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a> as <a class="trait" href="../../../../nom/lib/std/slice/trait.Join.html" title="trait nom::lib::std::slice::Join">Join</a><Separator>>::<a class="type" href="../../../../nom/lib/std/slice/trait.Join.html#associatedtype.Output" title="type nom::lib::std::slice::Join::Output">Output</a> <span class="where fmt-newline">where<br> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>: <a class="trait" href="../../../../nom/lib/std/slice/trait.Join.html" title="trait nom::lib::std::slice::Join">Join</a><Separator>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#543-548' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab deprecated'>Deprecated since 1.3.0: <p>renamed to join</p>
|
||
</div></div><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>
|
||
<h1 id="examples-115" class="section-header"><a href="#examples-115">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="macro">assert_eq</span><span class="macro">!</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="macro">!</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>]);</pre></div>
|
||
</div></div><div class='impl-items'><h4 id='method.to_ascii_uppercase' class="method"><code id='to_ascii_uppercase.v'>pub fn <a href='#method.to_ascii_uppercase' class='fnname'>to_ascii_uppercase</a>(&self) -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>></code><span class='since' title='Stable since Rust version 1.23.0'>1.23.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#565-569' title='goto source code'>[src]</a></h4><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="#method.make_ascii_uppercase"><code>make_ascii_uppercase</code></a>.</p>
|
||
</div><h4 id='method.to_ascii_lowercase' class="method"><code id='to_ascii_lowercase.v'>pub fn <a href='#method.to_ascii_lowercase' class='fnname'>to_ascii_lowercase</a>(&self) -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>></code><span class='since' title='Stable since Rust version 1.23.0'>1.23.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#582-586' title='goto source code'>[src]</a></h4><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="#method.make_ascii_lowercase"><code>make_ascii_lowercase</code></a>.</p>
|
||
</div></div><h2 id='implementations' class='small-section-header'>Trait Implementations<a href='#implementations' class='anchor'></a></h2><div id='implementations-list'><h3 id='impl-AsMut%3C%5BT%5D%3E' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.AsMut.html" title="trait nom::lib::std::prelude::v1::v1::AsMut">AsMut</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl-AsMut%3C%5BT%5D%3E' class='anchor'></a><span class='since' title='Stable since Rust version 1.5.0'>1.5.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2370-2374' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.as_mut' class="method hidden"><code id='as_mut.v'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.AsMut.html#tymethod.as_mut' class='fnname'>as_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2371-2373' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-AsMut%3CVec%3CT%3E%3E' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.AsMut.html" title="trait nom::lib::std::prelude::v1::v1::AsMut">AsMut</a><<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl-AsMut%3CVec%3CT%3E%3E' class='anchor'></a><span class='since' title='Stable since Rust version 1.5.0'>1.5.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2356-2360' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.as_mut-1' class="method hidden"><code id='as_mut.v-1'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.AsMut.html#tymethod.as_mut' class='fnname'>as_mut</a>(&mut self) -> &mut <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2357-2359' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-AsRef%3C%5BT%5D%3E' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.AsRef.html" title="trait nom::lib::std::prelude::v1::v1::AsRef">AsRef</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl-AsRef%3C%5BT%5D%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2363-2367' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.as_ref' class="method hidden"><code id='as_ref.v'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.AsRef.html#tymethod.as_ref' class='fnname'>as_ref</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[T]</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2364-2366' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-AsRef%3CVec%3CT%3E%3E' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.AsRef.html" title="trait nom::lib::std::prelude::v1::v1::AsRef">AsRef</a><<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl-AsRef%3CVec%3CT%3E%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2349-2353' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.as_ref-1' class="method hidden"><code id='as_ref.v-1'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.AsRef.html#tymethod.as_ref' class='fnname'>as_ref</a>(&self) -> &<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2350-2352' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-Borrow%3C%5BT%5D%3E' class='impl'><code class='in-band'>impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl-Borrow%3C%5BT%5D%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#709-713' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.borrow' class="method hidden"><code id='borrow.v'>fn <a href='https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow' class='fnname'>borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[T]</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#710-712' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p>
|
||
</div></div><h3 id='impl-BorrowMut%3C%5BT%5D%3E' class='impl'><code class='in-band'>impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl-BorrowMut%3C%5BT%5D%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#716-720' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.borrow_mut' class="method hidden"><code id='borrow_mut.v'>fn <a href='https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut' class='fnname'>borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/slice.rs.html#717-719' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></p>
|
||
</div></div><h3 id='impl-Clone' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Clone.html" title="trait nom::lib::std::prelude::v1::v1::Clone">Clone</a> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Clone.html" title="trait nom::lib::std::prelude::v1::v1::Clone">Clone</a>, </span></code><a href='#impl-Clone' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1852-1870' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.clone' class="method hidden"><code id='clone.v'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.Clone.html#tymethod.clone' class='fnname'>clone</a>(&self) -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1854-1856' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Returns a copy of the value. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.Clone.html#tymethod.clone">Read more</a></p>
|
||
</div><h4 id='method.clone_from' class="method hidden"><code id='clone_from.v'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.Clone.html#method.clone_from' class='fnname'>clone_from</a>(&mut self, other: &<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>)</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1867-1869' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs copy-assignment from <code>source</code>. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.Clone.html#method.clone_from">Read more</a></p>
|
||
</div></div><h3 id='impl-Debug' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/fmt/trait.Debug.html" title="trait nom::lib::std::fmt::Debug">Debug</a> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/fmt/trait.Debug.html" title="trait nom::lib::std::fmt::Debug">Debug</a>, </span></code><a href='#impl-Debug' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2342-2346' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.fmt' class="method hidden"><code id='fmt.v'>fn <a href='../../../../nom/lib/std/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&self, f: &mut <a class="struct" href="../../../../nom/lib/std/fmt/struct.Formatter.html" title="struct nom::lib::std::fmt::Formatter">Formatter</a>) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Result.html" title="enum nom::lib::std::prelude::v1::v1::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="struct" href="../../../../nom/lib/std/fmt/struct.Error.html" title="struct nom::lib::std::fmt::Error">Error</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2343-2345' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Formats the value using the given formatter. <a href="../../../../nom/lib/std/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
|
||
</div></div><h3 id='impl-Default' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Default.html" title="trait nom::lib::std::prelude::v1::v1::Default">Default</a> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl-Default' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2334-2339' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.default' class="method"><code id='default.v'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.Default.html#tymethod.default' class='fnname'>default</a>() -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2336-2338' title='goto source code'>[src]</a></h4><div class='docblock'><p>Creates an empty <code>Vec<T></code>.</p>
|
||
</div></div><h3 id='impl-Deref' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/ops/trait.Deref.html" title="trait nom::lib::std::ops::Deref">Deref</a> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl-Deref' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1907-1913' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Target' class="type"><code id='Target.t'>type <a href='../../../../nom/lib/std/ops/trait.Deref.html#associatedtype.Target' class="type">Target</a> = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a></code></h4><div class='docblock'><p>The resulting type after dereferencing.</p>
|
||
</div><h4 id='method.deref' class="method hidden"><code id='deref.v'>fn <a href='../../../../nom/lib/std/ops/trait.Deref.html#tymethod.deref' class='fnname'>deref</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[T]</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1910-1912' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Dereferences the value.</p>
|
||
</div></div><h3 id='impl-DerefMut' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/ops/trait.DerefMut.html" title="trait nom::lib::std::ops::DerefMut">DerefMut</a> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl-DerefMut' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1916-1920' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.deref_mut' class="method hidden"><code id='deref_mut.v'>fn <a href='../../../../nom/lib/std/ops/trait.DerefMut.html#tymethod.deref_mut' class='fnname'>deref_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1917-1919' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Mutably dereferences the value.</p>
|
||
</div></div><h3 id='impl-Drop' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Drop.html" title="trait nom::lib::std::prelude::v1::v1::Drop">Drop</a> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl-Drop' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2323-2331' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.drop' class="method hidden"><code id='drop.v'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.Drop.html#tymethod.drop' class='fnname'>drop</a>(&mut self)</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2324-2330' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Executes the destructor for this type. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.Drop.html#tymethod.drop">Read more</a></p>
|
||
</div></div><h3 id='impl-Eq' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Eq.html" title="trait nom::lib::std::prelude::v1::v1::Eq">Eq</a> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Eq.html" title="trait nom::lib::std::prelude::v1::v1::Eq">Eq</a>, </span></code><a href='#impl-Eq' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2311' title='goto source code'>[src]</a></h3><div class='impl-items'></div><h3 id='impl-Extend%3C%26%27a%20T%3E' class='impl'><code class='in-band'>impl<'a, T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Extend.html" title="trait nom::lib::std::prelude::v1::v1::Extend">Extend</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a </a>T> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> T: 'a + <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Copy.html" title="trait nom::lib::std::prelude::v1::v1::Copy">Copy</a>, </span></code><a href='#impl-Extend%3C%26%27a%20T%3E' class='anchor'></a><span class='since' title='Stable since Rust version 1.2.0'>1.2.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2263-2267' title='goto source code'>[src]</a></h3><div class='docblock'><p>Extend implementation that copies elements out of references before pushing them onto the Vec.</p>
|
||
<p>This implementation is specialized for slice iterators, where it uses <a href="../../std/primitive.slice.html#method.copy_from_slice"><code>copy_from_slice</code></a> to
|
||
append the entire slice at once.</p>
|
||
</div><div class='impl-items'><h4 id='method.extend-1' class="method hidden"><code id='extend.v-1'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.Extend.html#tymethod.extend' class='fnname'>extend</a><I>(&mut self, iter: I) <span class="where fmt-newline">where<br> I: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html" title="trait nom::lib::std::prelude::v1::v1::IntoIterator">IntoIterator</a><Item = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a </a>T>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2264-2266' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Extends a collection with the contents of an iterator. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.Extend.html#tymethod.extend">Read more</a></p>
|
||
</div></div><h3 id='impl-Extend%3CT%3E' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Extend.html" title="trait nom::lib::std::prelude::v1::v1::Extend">Extend</a><T> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl-Extend%3CT%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1991-1996' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.extend' class="method hidden"><code id='extend.v'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.Extend.html#tymethod.extend' class='fnname'>extend</a><I>(&mut self, iter: I) <span class="where fmt-newline">where<br> I: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html" title="trait nom::lib::std::prelude::v1::v1::IntoIterator">IntoIterator</a><Item = T>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1993-1995' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Extends a collection with the contents of an iterator. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.Extend.html#tymethod.extend">Read more</a></p>
|
||
</div></div><h3 id='impl-From%3C%26%27_%20%5BT%5D%3E' class='impl'><code class='in-band'>impl<'_, T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.From.html" title="trait nom::lib::std::prelude::v1::v1::From">From</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&'_ [T]</a>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Clone.html" title="trait nom::lib::std::prelude::v1::v1::Clone">Clone</a>, </span></code><a href='#impl-From%3C%26%27_%20%5BT%5D%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2377-2386' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-15' class="method hidden"><code id='from.v-15'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.From.html#tymethod.from' class='fnname'>from</a>(s: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[T]</a>) -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2379-2381' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-From%3C%26%27_%20mut%20%5BT%5D%3E' class='impl'><code class='in-band'>impl<'_, T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.From.html" title="trait nom::lib::std::prelude::v1::v1::From">From</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&'_ mut [T]</a>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Clone.html" title="trait nom::lib::std::prelude::v1::v1::Clone">Clone</a>, </span></code><a href='#impl-From%3C%26%27_%20mut%20%5BT%5D%3E' class='anchor'></a><span class='since' title='Stable since Rust version 1.19.0'>1.19.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2389-2398' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-2' class="method hidden"><code id='from.v-2'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.From.html#tymethod.from' class='fnname'>from</a>(s: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [T]</a>) -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2391-2393' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-From%3C%26%27_%20str%3E' class='impl'><code class='in-band'>impl<'_> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.From.html" title="trait nom::lib::std::prelude::v1::v1::From">From</a><&'_ <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>></code><a href='#impl-From%3C%26%27_%20str%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2429-2433' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-5' class="method hidden"><code id='from.v-5'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.From.html#tymethod.from' class='fnname'>from</a>(s: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2430-2432' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-From%3C%26%27a%20Vec%3CT%3E%3E' class='impl'><code class='in-band'>impl<'a, T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.From.html" title="trait nom::lib::std::prelude::v1::v1::From">From</a><&'a <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>> for <a class="enum" href="https://doc.rust-lang.org/nightly/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Clone.html" title="trait nom::lib::std::prelude::v1::v1::Clone">Clone</a>, </span></code><a href='#impl-From%3C%26%27a%20Vec%3CT%3E%3E' class='anchor'></a><span class='since' title='Stable since Rust version 1.28.0'>1.28.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2454-2458' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-13' class="method hidden"><code id='from.v-13'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.From.html#tymethod.from' class='fnname'>from</a>(v: &'a <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2455-2457' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-From%3CBinaryHeap%3CT%3E%3E' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.From.html" title="trait nom::lib::std::prelude::v1::v1::From">From</a><<a class="struct" href="../../../../nom/lib/std/collections/struct.BinaryHeap.html" title="struct nom::lib::std::collections::BinaryHeap">BinaryHeap</a><T>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl-From%3CBinaryHeap%3CT%3E%3E' class='anchor'></a><span class='since' title='Stable since Rust version 1.5.0'>1.5.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/collections/binary_heap.rs.html#1296-1300' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-14' class="method hidden"><code id='from.v-14'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.From.html#tymethod.from' class='fnname'>from</a>(heap: <a class="struct" href="../../../../nom/lib/std/collections/struct.BinaryHeap.html" title="struct nom::lib::std::collections::BinaryHeap">BinaryHeap</a><T>) -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/collections/binary_heap.rs.html#1297-1299' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-From%3CBox%3C%5BT%5D%3E%3E' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.From.html" title="trait nom::lib::std::prelude::v1::v1::From">From</a><<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Box.html" title="struct nom::lib::std::prelude::v1::v1::Box">Box</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl-From%3CBox%3C%5BT%5D%3E%3E' class='anchor'></a><span class='since' title='Stable since Rust version 1.18.0'>1.18.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2413-2417' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-10' class="method hidden"><code id='from.v-10'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.From.html#tymethod.from' class='fnname'>from</a>(s: <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Box.html" title="struct nom::lib::std::prelude::v1::v1::Box">Box</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>) -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2414-2416' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-From%3CCString%3E' class='impl'><code class='in-band'>impl <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.From.html" title="trait nom::lib::std::prelude::v1::v1::From">From</a><<a class="struct" href="https://doc.rust-lang.org/nightly/std/ffi/c_str/struct.CString.html" title="struct std::ffi::c_str::CString">CString</a>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>></code><a href='#impl-From%3CCString%3E' class='anchor'></a><span class='since' title='Stable since Rust version 1.7.0'>1.7.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/ffi/c_str.rs.html#668-679' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-1' class="method"><code id='from.v-1'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.From.html#tymethod.from' class='fnname'>from</a>(s: <a class="struct" href="https://doc.rust-lang.org/nightly/std/ffi/c_str/struct.CString.html" title="struct std::ffi::c_str::CString">CString</a>) -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/ffi/c_str.rs.html#676-678' title='goto source code'>[src]</a></h4><div class='docblock'><p>Converts a <a href="../ffi/struct.CString.html"><code>CString</code></a> into a <a href="../vec/struct.Vec.html"><code>Vec</code></a><code><u8></code>.</p>
|
||
<p>The conversion consumes the <a href="../ffi/struct.CString.html"><code>CString</code></a>, and removes the terminating NUL byte.</p>
|
||
</div></div><h3 id='impl-From%3CCow%3C%27a%2C%20%5BT%5D%3E%3E' class='impl'><code class='in-band'>impl<'a, T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.From.html" title="trait nom::lib::std::prelude::v1::v1::From">From</a><<a class="enum" href="https://doc.rust-lang.org/nightly/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.ToOwned.html" title="trait nom::lib::std::prelude::v1::v1::ToOwned">ToOwned</a>,<br> <<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a> as <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.ToOwned.html" title="trait nom::lib::std::prelude::v1::v1::ToOwned">ToOwned</a>>::<a class="type" href="../../../../nom/lib/std/prelude/v1/v1/trait.ToOwned.html#associatedtype.Owned" title="type nom::lib::std::prelude::v1::v1::ToOwned::Owned">Owned</a> == <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>, </span></code><a href='#impl-From%3CCow%3C%27a%2C%20%5BT%5D%3E%3E' class='anchor'></a><span class='since' title='Stable since Rust version 1.14.0'>1.14.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2401-2408' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-8' class="method hidden"><code id='from.v-8'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.From.html#tymethod.from' class='fnname'>from</a>(s: <a class="enum" href="https://doc.rust-lang.org/nightly/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>) -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2405-2407' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-From%3CString%3E' class='impl'><code class='in-band'>impl <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.From.html" title="trait nom::lib::std::prelude::v1::v1::From">From</a><<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.String.html" title="struct nom::lib::std::prelude::v1::v1::String">String</a>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>></code><a href='#impl-From%3CString%3E' class='anchor'></a><span class='since' title='Stable since Rust version 1.14.0'>1.14.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/string.rs.html#2332-2350' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-3' class="method"><code id='from.v-3'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.From.html#tymethod.from' class='fnname'>from</a>(string: <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.String.html" title="struct nom::lib::std::prelude::v1::v1::String">String</a>) -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/string.rs.html#2347-2349' title='goto source code'>[src]</a></h4><div class='docblock'><p>Converts the given <code>String</code> to a vector <code>Vec</code> that holds values of type <code>u8</code>.</p>
|
||
<h1 id="examples-117" class="section-header"><a href="#examples-117">Examples</a></h1>
|
||
<p>Basic usage:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">s1</span> <span class="op">=</span> <span class="ident">String</span>::<span class="ident">from</span>(<span class="string">"hello world"</span>);
|
||
<span class="kw">let</span> <span class="ident">v1</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">from</span>(<span class="ident">s1</span>);
|
||
|
||
<span class="kw">for</span> <span class="ident">b</span> <span class="kw">in</span> <span class="ident">v1</span> {
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">b</span>);
|
||
}</pre></div>
|
||
</div></div><h3 id='impl-From%3CVec%3CNonZeroU8%3E%3E' class='impl'><code class='in-band'>impl <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.From.html" title="trait nom::lib::std::prelude::v1::v1::From">From</a><<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><<a class="struct" href="https://doc.rust-lang.org/nightly/core/num/struct.NonZeroU8.html" title="struct core::num::NonZeroU8">NonZeroU8</a>>> for <a class="struct" href="https://doc.rust-lang.org/nightly/std/ffi/c_str/struct.CString.html" title="struct std::ffi::c_str::CString">CString</a></code><a href='#impl-From%3CVec%3CNonZeroU8%3E%3E' class='anchor'></a><span class='since' title='Stable since Rust version 1.43.0'>1.43.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/ffi/c_str.rs.html#746-769' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from' class="method"><code id='from.v'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.From.html#tymethod.from' class='fnname'>from</a>(v: <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><<a class="struct" href="https://doc.rust-lang.org/nightly/core/num/struct.NonZeroU8.html" title="struct core::num::NonZeroU8">NonZeroU8</a>>) -> <a class="struct" href="https://doc.rust-lang.org/nightly/std/ffi/c_str/struct.CString.html" title="struct std::ffi::c_str::CString">CString</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/ffi/c_str.rs.html#754-768' title='goto source code'>[src]</a></h4><div class='docblock'><p>Converts a <a href="../vec/struct.Vec.html"><code>Vec</code></a><code><</code><a href="../num/struct.NonZeroU8.html"><code>NonZeroU8</code></a><code>></code> into a <a href="../ffi/struct.CString.html"><code>CString</code></a> without
|
||
copying nor checking for inner null bytes.</p>
|
||
</div></div><h3 id='impl-From%3CVec%3CT%3E%3E' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.From.html" title="trait nom::lib::std::prelude::v1::v1::From">From</a><<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>> for <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/rc/struct.Rc.html" title="struct alloc::rc::Rc">Rc</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>></code><a href='#impl-From%3CVec%3CT%3E%3E' class='anchor'></a><span class='since' title='Stable since Rust version 1.21.0'>1.21.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/rc.rs.html#1442-1454' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-4' class="method hidden"><code id='from.v-4'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.From.html#tymethod.from' class='fnname'>from</a>(v: <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>) -> <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/rc/struct.Rc.html" title="struct alloc::rc::Rc">Rc</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/rc.rs.html#1444-1453' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-From%3CVec%3CT%3E%3E-1' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.From.html" title="trait nom::lib::std::prelude::v1::v1::From">From</a><<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>> for <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/sync/struct.Arc.html" title="struct alloc::sync::Arc">Arc</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>></code><a href='#impl-From%3CVec%3CT%3E%3E-1' class='anchor'></a><span class='since' title='Stable since Rust version 1.21.0'>1.21.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/sync.rs.html#1991-2003' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-6' class="method hidden"><code id='from.v-6'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.From.html#tymethod.from' class='fnname'>from</a>(v: <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>) -> <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/sync/struct.Arc.html" title="struct alloc::sync::Arc">Arc</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/sync.rs.html#1993-2002' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-From%3CVec%3CT%3E%3E-2' class='impl'><code class='in-band'>impl<'a, T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.From.html" title="trait nom::lib::std::prelude::v1::v1::From">From</a><<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>> for <a class="enum" href="https://doc.rust-lang.org/nightly/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Clone.html" title="trait nom::lib::std::prelude::v1::v1::Clone">Clone</a>, </span></code><a href='#impl-From%3CVec%3CT%3E%3E-2' class='anchor'></a><span class='since' title='Stable since Rust version 1.8.0'>1.8.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2447-2451' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-7' class="method hidden"><code id='from.v-7'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.From.html#tymethod.from' class='fnname'>from</a>(v: <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'a, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2448-2450' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-From%3CVec%3CT%3E%3E-3' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.From.html" title="trait nom::lib::std::prelude::v1::v1::From">From</a><<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>> for <a class="struct" href="../../../../nom/lib/std/collections/struct.VecDeque.html" title="struct nom::lib::std::collections::VecDeque">VecDeque</a><T></code><a href='#impl-From%3CVec%3CT%3E%3E-3' class='anchor'></a><span class='since' title='Stable since Rust version 1.10.0'>1.10.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/collections/vec_deque.rs.html#2743-2772' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-9' class="method"><code id='from.v-9'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.From.html#tymethod.from' class='fnname'>from</a>(other: <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>) -> <a class="struct" href="../../../../nom/lib/std/collections/struct.VecDeque.html" title="struct nom::lib::std::collections::VecDeque">VecDeque</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/collections/vec_deque.rs.html#2752-2771' title='goto source code'>[src]</a></h4><div class='docblock'><p>Turn a <a href="crate::vec::Vec"><code>Vec<T></code></a> into a <a href="crate::collections::VecDeque"><code>VecDeque<T></code></a>.</p>
|
||
<p>This avoids reallocating where possible, but the conditions for that are
|
||
strict, and subject to change, and so shouldn't be relied upon unless the
|
||
<code>Vec<T></code> came from <code>From<VecDeque<T>></code> and hasn't been reallocated.</p>
|
||
</div></div><h3 id='impl-From%3CVec%3CT%3E%3E-4' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.From.html" title="trait nom::lib::std::prelude::v1::v1::From">From</a><<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Box.html" title="struct nom::lib::std::prelude::v1::v1::Box">Box</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>></code><a href='#impl-From%3CVec%3CT%3E%3E-4' class='anchor'></a><span class='since' title='Stable since Rust version 1.20.0'>1.20.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2422-2426' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-11' class="method hidden"><code id='from.v-11'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.From.html#tymethod.from' class='fnname'>from</a>(v: <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>) -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Box.html" title="struct nom::lib::std::prelude::v1::v1::Box">Box</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2423-2425' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-From%3CVec%3CT%3E%3E-5' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.From.html" title="trait nom::lib::std::prelude::v1::v1::From">From</a><<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>> for <a class="struct" href="../../../../nom/lib/std/collections/struct.BinaryHeap.html" title="struct nom::lib::std::collections::BinaryHeap">BinaryHeap</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Ord.html" title="trait nom::lib::std::prelude::v1::v1::Ord">Ord</a>, </span></code><a href='#impl-From%3CVec%3CT%3E%3E-5' class='anchor'></a><span class='since' title='Stable since Rust version 1.5.0'>1.5.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/collections/binary_heap.rs.html#1284-1293' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-16' class="method"><code id='from.v-16'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.From.html#tymethod.from' class='fnname'>from</a>(vec: <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>) -> <a class="struct" href="../../../../nom/lib/std/collections/struct.BinaryHeap.html" title="struct nom::lib::std::collections::BinaryHeap">BinaryHeap</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/collections/binary_heap.rs.html#1288-1292' title='goto source code'>[src]</a></h4><div class='docblock'><p>Converts a <code>Vec<T></code> into a <code>BinaryHeap<T></code>.</p>
|
||
<p>This conversion happens in-place, and has <code>O(n)</code> time complexity.</p>
|
||
</div></div><h3 id='impl-From%3CVecDeque%3CT%3E%3E' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.From.html" title="trait nom::lib::std::prelude::v1::v1::From">From</a><<a class="struct" href="../../../../nom/lib/std/collections/struct.VecDeque.html" title="struct nom::lib::std::collections::VecDeque">VecDeque</a><T>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl-From%3CVecDeque%3CT%3E%3E' class='anchor'></a><span class='since' title='Stable since Rust version 1.10.0'>1.10.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/collections/vec_deque.rs.html#2775-2868' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-12' class="method"><code id='from.v-12'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.From.html#tymethod.from' class='fnname'>from</a>(other: <a class="struct" href="../../../../nom/lib/std/collections/struct.VecDeque.html" title="struct nom::lib::std::collections::VecDeque">VecDeque</a><T>) -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/collections/vec_deque.rs.html#2805-2867' title='goto source code'>[src]</a></h4><div class='docblock'><p>Turn a <a href="crate::collections::VecDeque"><code>VecDeque<T></code></a> into a <a href="crate::vec::Vec"><code>Vec<T></code></a>.</p>
|
||
<p>This never needs to re-allocate, but does need to do O(n) data movement if
|
||
the circular buffer doesn't happen to be at the beginning of the allocation.</p>
|
||
<h1 id="examples-118" class="section-header"><a href="#examples-118">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">VecDeque</span>;
|
||
|
||
<span class="comment">// This one is O(1).</span>
|
||
<span class="kw">let</span> <span class="ident">deque</span>: <span class="ident">VecDeque</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> (<span class="number">1</span>..<span class="number">5</span>).<span class="ident">collect</span>();
|
||
<span class="kw">let</span> <span class="ident">ptr</span> <span class="op">=</span> <span class="ident">deque</span>.<span class="ident">as_slices</span>().<span class="number">0</span>.<span class="ident">as_ptr</span>();
|
||
<span class="kw">let</span> <span class="ident">vec</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">from</span>(<span class="ident">deque</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</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="macro">!</span>(<span class="ident">vec</span>.<span class="ident">as_ptr</span>(), <span class="ident">ptr</span>);
|
||
|
||
<span class="comment">// This one needs data rearranging.</span>
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">deque</span>: <span class="ident">VecDeque</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> (<span class="number">1</span>..<span class="number">5</span>).<span class="ident">collect</span>();
|
||
<span class="ident">deque</span>.<span class="ident">push_front</span>(<span class="number">9</span>);
|
||
<span class="ident">deque</span>.<span class="ident">push_front</span>(<span class="number">8</span>);
|
||
<span class="kw">let</span> <span class="ident">ptr</span> <span class="op">=</span> <span class="ident">deque</span>.<span class="ident">as_slices</span>().<span class="number">1</span>.<span class="ident">as_ptr</span>();
|
||
<span class="kw">let</span> <span class="ident">vec</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">from</span>(<span class="ident">deque</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">vec</span>, [<span class="number">8</span>, <span class="number">9</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="macro">!</span>(<span class="ident">vec</span>.<span class="ident">as_ptr</span>(), <span class="ident">ptr</span>);</pre></div>
|
||
</div></div><h3 id='impl-FromIterator%3CT%3E' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/iter/trait.FromIterator.html" title="trait nom::lib::std::iter::FromIterator">FromIterator</a><T> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl-FromIterator%3CT%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1923-1928' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from_iter' class="method hidden"><code id='from_iter.v'>fn <a href='../../../../nom/lib/std/iter/trait.FromIterator.html#tymethod.from_iter' class='fnname'>from_iter</a><I>(iter: I) -> <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> I: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html" title="trait nom::lib::std::prelude::v1::v1::IntoIterator">IntoIterator</a><Item = T>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1925-1927' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Creates a value from an iterator. <a href="../../../../nom/lib/std/iter/trait.FromIterator.html#tymethod.from_iter">Read more</a></p>
|
||
</div></div><h3 id='impl-Hash' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/hash/trait.Hash.html" title="trait nom::lib::std::hash::Hash">Hash</a> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/hash/trait.Hash.html" title="trait nom::lib::std::hash::Hash">Hash</a>, </span></code><a href='#impl-Hash' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1873-1878' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.hash' class="method hidden"><code id='hash.v'>fn <a href='../../../../nom/lib/std/hash/trait.Hash.html#tymethod.hash' class='fnname'>hash</a><H>(&self, state: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>H) <span class="where fmt-newline">where<br> H: <a class="trait" href="../../../../nom/lib/std/hash/trait.Hasher.html" title="trait nom::lib::std::hash::Hasher">Hasher</a>, </span></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1875-1877' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Feeds this value into the given [<code>Hasher</code>]. <a href="../../../../nom/lib/std/hash/trait.Hash.html#tymethod.hash">Read more</a></p>
|
||
</div><h4 id='method.hash_slice' class="method hidden"><code id='hash_slice.v'>fn <a href='../../../../nom/lib/std/hash/trait.Hash.html#method.hash_slice' class='fnname'>hash_slice</a><H>(data: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[Self]</a>, state: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>H) <span class="where fmt-newline">where<br> H: <a class="trait" href="../../../../nom/lib/std/hash/trait.Hasher.html" title="trait nom::lib::std::hash::Hasher">Hasher</a>, </span></code><span class='since' title='Stable since Rust version 1.3.0'>1.3.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/hash/mod.rs.html#194-201' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Feeds a slice of this type into the given [<code>Hasher</code>]. <a href="../../../../nom/lib/std/hash/trait.Hash.html#method.hash_slice">Read more</a></p>
|
||
</div></div><h3 id='impl-Index%3CI%3E' class='impl'><code class='in-band'>impl<T, I> <a class="trait" href="../../../../nom/lib/std/ops/trait.Index.html" title="trait nom::lib::std::ops::Index">Index</a><I> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> I: <a class="trait" href="../../../../nom/lib/std/slice/trait.SliceIndex.html" title="trait nom::lib::std::slice::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>, </span></code><a href='#impl-Index%3CI%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1885-1892' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Output' class="type"><code id='Output.t'>type <a href='../../../../nom/lib/std/ops/trait.Index.html#associatedtype.Output' class="type">Output</a> = <I as <a class="trait" href="../../../../nom/lib/std/slice/trait.SliceIndex.html" title="trait nom::lib::std::slice::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>>::<a class="type" href="../../../../nom/lib/std/slice/trait.SliceIndex.html#associatedtype.Output" title="type nom::lib::std::slice::SliceIndex::Output">Output</a></code></h4><div class='docblock'><p>The returned type after indexing.</p>
|
||
</div><h4 id='method.index' class="method hidden"><code id='index.v'>fn <a href='../../../../nom/lib/std/ops/trait.Index.html#tymethod.index' class='fnname'>index</a>(&self, index: I) -> &<<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> as <a class="trait" href="../../../../nom/lib/std/ops/trait.Index.html" title="trait nom::lib::std::ops::Index">Index</a><I>>::<a class="type" href="../../../../nom/lib/std/ops/trait.Index.html#associatedtype.Output" title="type nom::lib::std::ops::Index::Output">Output</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1889-1891' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the indexing (<code>container[index]</code>) operation.</p>
|
||
</div></div><h3 id='impl-IndexMut%3CI%3E' class='impl'><code class='in-band'>impl<T, I> <a class="trait" href="../../../../nom/lib/std/ops/trait.IndexMut.html" title="trait nom::lib::std::ops::IndexMut">IndexMut</a><I> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> I: <a class="trait" href="../../../../nom/lib/std/slice/trait.SliceIndex.html" title="trait nom::lib::std::slice::SliceIndex">SliceIndex</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>, </span></code><a href='#impl-IndexMut%3CI%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1899-1904' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.index_mut' class="method hidden"><code id='index_mut.v'>fn <a href='../../../../nom/lib/std/ops/trait.IndexMut.html#tymethod.index_mut' class='fnname'>index_mut</a>(&mut self, index: I) -> &mut <<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> as <a class="trait" href="../../../../nom/lib/std/ops/trait.Index.html" title="trait nom::lib::std::ops::Index">Index</a><I>>::<a class="type" href="../../../../nom/lib/std/ops/trait.Index.html#associatedtype.Output" title="type nom::lib::std::ops::Index::Output">Output</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1901-1903' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the mutable indexing (<code>container[index]</code>) operation.</p>
|
||
</div></div><h3 id='impl-IntoIterator' class='impl'><code class='in-band'>impl<'a, T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html" title="trait nom::lib::std::prelude::v1::v1::IntoIterator">IntoIterator</a> for &'a <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl-IntoIterator' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1971-1978' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Item' class="type"><code id='Item.t'>type <a href='../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html#associatedtype.Item' class="type">Item</a> = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a </a>T</code></h4><div class='docblock'><p>The type of the elements being iterated over.</p>
|
||
</div><h4 id='associatedtype.IntoIter' class="type"><code id='IntoIter.t'>type <a href='../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html#associatedtype.IntoIter' class="type">IntoIter</a> = <a class="struct" href="../../../../nom/lib/std/slice/struct.Iter.html" title="struct nom::lib::std::slice::Iter">Iter</a><'a, T></code></h4><div class='docblock'><p>Which kind of iterator are we turning this into?</p>
|
||
</div><h4 id='method.into_iter' class="method hidden"><code id='into_iter.v'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html#tymethod.into_iter' class='fnname'>into_iter</a>(self) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.Iter.html" title="struct nom::lib::std::slice::Iter">Iter</a><'a, T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1975-1977' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Creates an iterator from a value. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html#tymethod.into_iter">Read more</a></p>
|
||
</div></div><h3 id='impl-IntoIterator-1' class='impl'><code class='in-band'>impl<'a, T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html" title="trait nom::lib::std::prelude::v1::v1::IntoIterator">IntoIterator</a> for &'a mut <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl-IntoIterator-1' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1981-1988' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Item-1' class="type"><code id='Item.t-1'>type <a href='../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html#associatedtype.Item' class="type">Item</a> = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>T</code></h4><div class='docblock'><p>The type of the elements being iterated over.</p>
|
||
</div><h4 id='associatedtype.IntoIter-1' class="type"><code id='IntoIter.t-1'>type <a href='../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html#associatedtype.IntoIter' class="type">IntoIter</a> = <a class="struct" href="../../../../nom/lib/std/slice/struct.IterMut.html" title="struct nom::lib::std::slice::IterMut">IterMut</a><'a, T></code></h4><div class='docblock'><p>Which kind of iterator are we turning this into?</p>
|
||
</div><h4 id='method.into_iter-1' class="method hidden"><code id='into_iter.v-1'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html#tymethod.into_iter' class='fnname'>into_iter</a>(self) -> <a class="struct" href="../../../../nom/lib/std/slice/struct.IterMut.html" title="struct nom::lib::std::slice::IterMut">IterMut</a><'a, T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1985-1987' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Creates an iterator from a value. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html#tymethod.into_iter">Read more</a></p>
|
||
</div></div><h3 id='impl-IntoIterator-2' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html" title="trait nom::lib::std::prelude::v1::v1::IntoIterator">IntoIterator</a> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T></code><a href='#impl-IntoIterator-2' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1931-1968' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Item-2' class="type"><code id='Item.t-2'>type <a href='../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html#associatedtype.Item' class="type">Item</a> = T</code></h4><div class='docblock'><p>The type of the elements being iterated over.</p>
|
||
</div><h4 id='associatedtype.IntoIter-2' class="type"><code id='IntoIter.t-2'>type <a href='../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html#associatedtype.IntoIter' class="type">IntoIter</a> = <a class="struct" href="../../../../nom/lib/std/vec/struct.IntoIter.html" title="struct nom::lib::std::vec::IntoIter">IntoIter</a><T></code></h4><div class='docblock'><p>Which kind of iterator are we turning this into?</p>
|
||
</div><h4 id='method.into_iter-2' class="method"><code id='into_iter.v-2'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html#tymethod.into_iter' class='fnname'>into_iter</a>(self) -> <a class="struct" href="../../../../nom/lib/std/vec/struct.IntoIter.html" title="struct nom::lib::std::vec::IntoIter">IntoIter</a><T></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#1949-1967' title='goto source code'>[src]</a></h4><div class='docblock'><p>Creates a consuming iterator, that is, one that moves each value out of
|
||
the vector (from start to end). The vector cannot be used after calling
|
||
this.</p>
|
||
<h1 id="examples-116" class="section-header"><a href="#examples-116">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">v</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="string">"a"</span>.<span class="ident">to_string</span>(), <span class="string">"b"</span>.<span class="ident">to_string</span>()];
|
||
<span class="kw">for</span> <span class="ident">s</span> <span class="kw">in</span> <span class="ident">v</span>.<span class="ident">into_iter</span>() {
|
||
<span class="comment">// s has type String, not &String</span>
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">s</span>);
|
||
}</pre></div>
|
||
</div></div><h3 id='impl-Ord' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Ord.html" title="trait nom::lib::std::prelude::v1::v1::Ord">Ord</a> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Ord.html" title="trait nom::lib::std::prelude::v1::v1::Ord">Ord</a>, </span></code><a href='#impl-Ord' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2315-2320' title='goto source code'>[src]</a></h3><div class='docblock'><p>Implements ordering of vectors, lexicographically.</p>
|
||
</div><div class='impl-items'><h4 id='method.cmp' class="method hidden"><code id='cmp.v'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.Ord.html#tymethod.cmp' class='fnname'>cmp</a>(&self, other: &<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>) -> <a class="enum" href="../../../../nom/lib/std/cmp/enum.Ordering.html" title="enum nom::lib::std::cmp::Ordering">Ordering</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2317-2319' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method returns an [<code>Ordering</code>] between <code>self</code> and <code>other</code>. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.Ord.html#tymethod.cmp">Read more</a></p>
|
||
</div><h4 id='method.max' class="method hidden"><code id='max.v'><span class="docblock attributes">#[must_use]
|
||
</span>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.Ord.html#method.max' class='fnname'>max</a>(self, other: Self) -> Self</code><span class='since' title='Stable since Rust version 1.21.0'>1.21.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/cmp.rs.html#599-604' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Compares and returns the maximum of two values. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.Ord.html#method.max">Read more</a></p>
|
||
</div><h4 id='method.min' class="method hidden"><code id='min.v'><span class="docblock attributes">#[must_use]
|
||
</span>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.Ord.html#method.min' class='fnname'>min</a>(self, other: Self) -> Self</code><span class='since' title='Stable since Rust version 1.21.0'>1.21.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/cmp.rs.html#619-624' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Compares and returns the minimum of two values. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.Ord.html#method.min">Read more</a></p>
|
||
</div><h4 id='method.clamp' class="method hidden"><code id='clamp.v'><span class="docblock attributes">#[must_use]
|
||
</span>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.Ord.html#method.clamp' class='fnname'>clamp</a>(self, min: Self, max: Self) -> Self</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/cmp.rs.html#646-658' title='goto source code'>[src]</a></h4><div class='stability hidden'><div class='stab unstable'><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>clamp</code>)</div></div><div class='docblock hidden'><p>Restrict a value to a certain interval. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.Ord.html#method.clamp">Read more</a></p>
|
||
</div></div><h3 id='impl-PartialEq%3C%26%27_%20%5BB%3B%20N%5D%3E' class='impl'><code class='in-band'>impl<'_, const N: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, A, B> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><&'_ <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">[</a>B<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">; N]</a>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><A> <span class="where fmt-newline">where<br> A: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><B>,<br> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">[</a>B<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">; N]</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/array/trait.LengthAtMost32.html" title="trait core::array::LengthAtMost32">LengthAtMost32</a>, </span></code><a href='#impl-PartialEq%3C%26%27_%20%5BB%3B%20N%5D%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2272-2281' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.eq-6' class="method hidden"><code id='eq.v-6'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&self, other: &&<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">[</a>B<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">; N]</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2278' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#tymethod.eq">Read more</a></p>
|
||
</div><h4 id='method.ne-6' class="method hidden"><code id='ne.v-6'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&self, other: &&<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">[</a>B<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">; N]</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2280' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>!=</code>.</p>
|
||
</div></div><h3 id='impl-PartialEq%3C%26%27_%20%5BB%5D%3E' class='impl'><code class='in-band'>impl<'_, A, B> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&'_ [B]</a>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><A> <span class="where fmt-newline">where<br> A: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><B>, </span></code><a href='#impl-PartialEq%3C%26%27_%20%5BB%5D%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2272-2281' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.eq-1' class="method hidden"><code id='eq.v-1'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&self, other: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[B]</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2278' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#tymethod.eq">Read more</a></p>
|
||
</div><h4 id='method.ne-1' class="method hidden"><code id='ne.v-1'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&self, other: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[B]</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2280' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>!=</code>.</p>
|
||
</div></div><h3 id='impl-PartialEq%3C%26%27_%20mut%20%5BB%5D%3E' class='impl'><code class='in-band'>impl<'_, A, B> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&'_ mut [B]</a>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><A> <span class="where fmt-newline">where<br> A: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><B>, </span></code><a href='#impl-PartialEq%3C%26%27_%20mut%20%5BB%5D%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2272-2281' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.eq' class="method hidden"><code id='eq.v'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&self, other: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [B]</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2278' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#tymethod.eq">Read more</a></p>
|
||
</div><h4 id='method.ne' class="method hidden"><code id='ne.v'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&self, other: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&mut [B]</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2280' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>!=</code>.</p>
|
||
</div></div><h3 id='impl-PartialEq%3C%5BB%3B%20N%5D%3E' class='impl'><code class='in-band'>impl<const N: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, A, B> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">[</a>B<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">; N]</a>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><A> <span class="where fmt-newline">where<br> A: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><B>,<br> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">[</a>B<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">; N]</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/array/trait.LengthAtMost32.html" title="trait core::array::LengthAtMost32">LengthAtMost32</a>, </span></code><a href='#impl-PartialEq%3C%5BB%3B%20N%5D%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2272-2281' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.eq-2' class="method hidden"><code id='eq.v-2'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&self, other: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">[</a>B<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">; N]</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2278' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#tymethod.eq">Read more</a></p>
|
||
</div><h4 id='method.ne-2' class="method hidden"><code id='ne.v-2'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&self, other: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">[</a>B<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">; N]</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2280' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>!=</code>.</p>
|
||
</div></div><h3 id='impl-PartialEq%3CVec%3CB%3E%3E' class='impl'><code class='in-band'>impl<A, B> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><B>> for <a class="struct" href="../../../../nom/lib/std/collections/struct.VecDeque.html" title="struct nom::lib::std::collections::VecDeque">VecDeque</a><A> <span class="where fmt-newline">where<br> A: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><B>, </span></code><a href='#impl-PartialEq%3CVec%3CB%3E%3E' class='anchor'></a><span class='since' title='Stable since Rust version 1.17.0'>1.17.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/collections/vec_deque.rs.html#2594-2607' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.eq-3' class="method hidden"><code id='eq.v-3'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&self, other: &<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><B>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/collections/vec_deque.rs.html#2599-2606' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#tymethod.eq">Read more</a></p>
|
||
</div><h4 id='method.ne-3' class="method hidden"><code id='ne.v-3'><span class="docblock attributes">#[must_use]
|
||
</span>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&self, other: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>Rhs) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/cmp.rs.html#215-217' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>!=</code>.</p>
|
||
</div></div><h3 id='impl-PartialEq%3CVec%3CB%3E%3E-1' class='impl'><code class='in-band'>impl<'_, A, B> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><B>> for <a class="enum" href="https://doc.rust-lang.org/nightly/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'_, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a>A<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>> <span class="where fmt-newline">where<br> A: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><B> + <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Clone.html" title="trait nom::lib::std::prelude::v1::v1::Clone">Clone</a>, </span></code><a href='#impl-PartialEq%3CVec%3CB%3E%3E-1' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2272-2281' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.eq-4' class="method hidden"><code id='eq.v-4'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&self, other: &<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><B>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2278' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#tymethod.eq">Read more</a></p>
|
||
</div><h4 id='method.ne-4' class="method hidden"><code id='ne.v-4'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&self, other: &<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><B>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2280' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>!=</code>.</p>
|
||
</div></div><h3 id='impl-PartialEq%3CVec%3CB%3E%3E-2' class='impl'><code class='in-band'>impl<A, B> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><B>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><A> <span class="where fmt-newline">where<br> A: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html" title="trait nom::lib::std::prelude::v1::v1::PartialEq">PartialEq</a><B>, </span></code><a href='#impl-PartialEq%3CVec%3CB%3E%3E-2' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2272-2281' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.eq-5' class="method hidden"><code id='eq.v-5'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&self, other: &<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><B>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2278' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#tymethod.eq">Read more</a></p>
|
||
</div><h4 id='method.ne-5' class="method hidden"><code id='ne.v-5'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&self, other: &<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><B>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2280' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>!=</code>.</p>
|
||
</div></div><h3 id='impl-PartialOrd%3CVec%3CT%3E%3E' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialOrd.html" title="trait nom::lib::std::prelude::v1::v1::PartialOrd">PartialOrd</a><<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialOrd.html" title="trait nom::lib::std::prelude::v1::v1::PartialOrd">PartialOrd</a><T>, </span></code><a href='#impl-PartialOrd%3CVec%3CT%3E%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2303-2308' title='goto source code'>[src]</a></h3><div class='docblock'><p>Implements comparison of vectors, lexicographically.</p>
|
||
</div><div class='impl-items'><h4 id='method.partial_cmp' class="method hidden"><code id='partial_cmp.v'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.PartialOrd.html#tymethod.partial_cmp' class='fnname'>partial_cmp</a>(&self, other: &<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T>) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Option.html" title="enum nom::lib::std::prelude::v1::v1::Option">Option</a><<a class="enum" href="../../../../nom/lib/std/cmp/enum.Ordering.html" title="enum nom::lib::std::cmp::Ordering">Ordering</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#2305-2307' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method returns an ordering between <code>self</code> and <code>other</code> values if one exists. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialOrd.html#tymethod.partial_cmp">Read more</a></p>
|
||
</div><h4 id='method.lt' class="method hidden"><code id='lt.v'><span class="docblock attributes">#[must_use]
|
||
</span>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.PartialOrd.html#method.lt' class='fnname'>lt</a>(&self, other: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>Rhs) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/cmp.rs.html#841-843' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method tests less than (for <code>self</code> and <code>other</code>) and is used by the <code><</code> operator. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialOrd.html#method.lt">Read more</a></p>
|
||
</div><h4 id='method.le' class="method hidden"><code id='le.v'><span class="docblock attributes">#[must_use]
|
||
</span>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.PartialOrd.html#method.le' class='fnname'>le</a>(&self, other: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>Rhs) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/cmp.rs.html#860-862' title='goto source code'>[src]</a></h4><div class='docblock hidden'><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="../../../../nom/lib/std/prelude/v1/v1/trait.PartialOrd.html#method.le">Read more</a></p>
|
||
</div><h4 id='method.gt' class="method hidden"><code id='gt.v'><span class="docblock attributes">#[must_use]
|
||
</span>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.PartialOrd.html#method.gt' class='fnname'>gt</a>(&self, other: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>Rhs) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/cmp.rs.html#878-880' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method tests greater than (for <code>self</code> and <code>other</code>) and is used by the <code>></code> operator. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.PartialOrd.html#method.gt">Read more</a></p>
|
||
</div><h4 id='method.ge' class="method hidden"><code id='ge.v'><span class="docblock attributes">#[must_use]
|
||
</span>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.PartialOrd.html#method.ge' class='fnname'>ge</a>(&self, other: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>Rhs) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/cmp.rs.html#897-899' title='goto source code'>[src]</a></h4><div class='docblock hidden'><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="../../../../nom/lib/std/prelude/v1/v1/trait.PartialOrd.html#method.ge">Read more</a></p>
|
||
</div></div><h3 id='impl-Write' class='impl'><code class='in-band'>impl <a class="trait" href="https://doc.rust-lang.org/nightly/std/io/trait.Write.html" title="trait std::io::Write">Write</a> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>></code><a href='#impl-Write' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/impls.rs.html#337-364' title='goto source code'>[src]</a></h3><div class='docblock'><p>Write is implemented for <code>Vec<u8></code> by appending to the vector.
|
||
The vector will grow as needed.</p>
|
||
</div><div class='impl-items'><h4 id='method.write' class="method hidden"><code id='write.v'>fn <a href='https://doc.rust-lang.org/nightly/std/io/trait.Write.html#tymethod.write' class='fnname'>write</a>(&mut self, buf: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Result.html" title="enum nom::lib::std::prelude::v1::v1::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/std/io/error/struct.Error.html" title="struct std::io::error::Error">Error</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/impls.rs.html#339-342' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Write a buffer into this writer, returning how many bytes were written. <a href="https://doc.rust-lang.org/nightly/std/io/trait.Write.html#tymethod.write">Read more</a></p>
|
||
</div><h4 id='method.write_vectored' class="method hidden"><code id='write_vectored.v'>fn <a href='https://doc.rust-lang.org/nightly/std/io/trait.Write.html#method.write_vectored' class='fnname'>write_vectored</a>(&mut self, bufs: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[</a><a class="struct" href="https://doc.rust-lang.org/nightly/std/io/struct.IoSlice.html" title="struct std::io::IoSlice">IoSlice</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Result.html" title="enum nom::lib::std::prelude::v1::v1::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/std/io/error/struct.Error.html" title="struct std::io::error::Error">Error</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/impls.rs.html#345-352' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Like <code>write</code>, except that it writes from a slice of buffers. <a href="https://doc.rust-lang.org/nightly/std/io/trait.Write.html#method.write_vectored">Read more</a></p>
|
||
</div><h4 id='method.write_all' class="method hidden"><code id='write_all.v'>fn <a href='https://doc.rust-lang.org/nightly/std/io/trait.Write.html#method.write_all' class='fnname'>write_all</a>(&mut self, buf: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Result.html" title="enum nom::lib::std::prelude::v1::v1::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/std/io/error/struct.Error.html" title="struct std::io::error::Error">Error</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/impls.rs.html#355-358' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Attempts to write an entire buffer into this writer. <a href="https://doc.rust-lang.org/nightly/std/io/trait.Write.html#method.write_all">Read more</a></p>
|
||
</div><h4 id='method.flush' class="method hidden"><code id='flush.v'>fn <a href='https://doc.rust-lang.org/nightly/std/io/trait.Write.html#tymethod.flush' class='fnname'>flush</a>(&mut self) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Result.html" title="enum nom::lib::std::prelude::v1::v1::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/std/io/error/struct.Error.html" title="struct std::io::error::Error">Error</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/impls.rs.html#361-363' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Flush this output stream, ensuring that all intermediately buffered contents reach their destination. <a href="https://doc.rust-lang.org/nightly/std/io/trait.Write.html#tymethod.flush">Read more</a></p>
|
||
</div><h4 id='method.write_fmt' class="method hidden"><code id='write_fmt.v'>fn <a href='https://doc.rust-lang.org/nightly/std/io/trait.Write.html#method.write_fmt' class='fnname'>write_fmt</a>(&mut self, fmt: <a class="struct" href="../../../../nom/lib/std/fmt/struct.Arguments.html" title="struct nom::lib::std::fmt::Arguments">Arguments</a>) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Result.html" title="enum nom::lib::std::prelude::v1::v1::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/std/io/error/struct.Error.html" title="struct std::io::error::Error">Error</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/mod.rs.html#1405-1437' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Writes a formatted string into this writer, returning any error encountered. <a href="https://doc.rust-lang.org/nightly/std/io/trait.Write.html#method.write_fmt">Read more</a></p>
|
||
</div><h4 id='method.by_ref' class="method hidden"><code id='by_ref.v'>fn <a href='https://doc.rust-lang.org/nightly/std/io/trait.Write.html#method.by_ref' class='fnname'>by_ref</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>Self</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/mod.rs.html#1461-1466' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Creates a "by reference" adaptor for this instance of <code>Write</code>. <a href="https://doc.rust-lang.org/nightly/std/io/trait.Write.html#method.by_ref">Read more</a></p>
|
||
</div></div></div><h2 id='synthetic-implementations' class='small-section-header'>Auto Trait Implementations<a href='#synthetic-implementations' class='anchor'></a></h2><div id='synthetic-implementations-list'><h3 id='impl-RefUnwindSafe' class='impl'><code class='in-band'>impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.RefUnwindSafe.html" title="trait std::panic::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.RefUnwindSafe.html" title="trait std::panic::RefUnwindSafe">RefUnwindSafe</a>, </span></code><a href='#impl-RefUnwindSafe' class='anchor'></a></h3><div class='impl-items'></div><h3 id='impl-Send' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Send.html" title="trait nom::lib::std::prelude::v1::v1::Send">Send</a> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Send.html" title="trait nom::lib::std::prelude::v1::v1::Send">Send</a>, </span></code><a href='#impl-Send' class='anchor'></a></h3><div class='impl-items'></div><h3 id='impl-Sync' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Sync.html" title="trait nom::lib::std::prelude::v1::v1::Sync">Sync</a> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Sync.html" title="trait nom::lib::std::prelude::v1::v1::Sync">Sync</a>, </span></code><a href='#impl-Sync' class='anchor'></a></h3><div class='impl-items'></div><h3 id='impl-Unpin' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Unpin.html" title="trait nom::lib::std::prelude::v1::v1::Unpin">Unpin</a> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Unpin.html" title="trait nom::lib::std::prelude::v1::v1::Unpin">Unpin</a>, </span></code><a href='#impl-Unpin' class='anchor'></a></h3><div class='impl-items'></div><h3 id='impl-UnwindSafe' class='impl'><code class='in-band'>impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.UnwindSafe.html" title="trait std::panic::UnwindSafe">UnwindSafe</a> for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Vec.html" title="struct nom::lib::std::prelude::v1::v1::Vec">Vec</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.UnwindSafe.html" title="trait std::panic::UnwindSafe">UnwindSafe</a>, </span></code><a href='#impl-UnwindSafe' class='anchor'></a></h3><div class='impl-items'></div></div><h2 id='blanket-implementations' class='small-section-header'>Blanket Implementations<a href='#blanket-implementations' class='anchor'></a></h2><div id='blanket-implementations-list'><h3 id='impl-Any' class='impl'><code class='in-band'>impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T <span class="where fmt-newline">where<br> T: 'static + ?<a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Sized.html" title="trait nom::lib::std::prelude::v1::v1::Sized">Sized</a>, </span></code><a href='#impl-Any' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/any.rs.html#108-112' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.type_id' class="method hidden"><code id='type_id.v'>fn <a href='https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id' class='fnname'>type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/any.rs.html#109-111' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id">Read more</a></p>
|
||
</div></div><h3 id='impl-Borrow%3CT%3E' class='impl'><code class='in-band'>impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><T> for T <span class="where fmt-newline">where<br> T: ?<a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Sized.html" title="trait nom::lib::std::prelude::v1::v1::Sized">Sized</a>, </span></code><a href='#impl-Borrow%3CT%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#213-217' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.borrow-1' class="method hidden"><code id='borrow.v-1'>fn <a href='https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow' class='fnname'>borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#214-216' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p>
|
||
</div></div><h3 id='impl-BorrowMut%3CT%3E' class='impl'><code class='in-band'>impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><T> for T <span class="where fmt-newline">where<br> T: ?<a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Sized.html" title="trait nom::lib::std::prelude::v1::v1::Sized">Sized</a>, </span></code><a href='#impl-BorrowMut%3CT%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#220-224' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.borrow_mut-1' class="method hidden"><code id='borrow_mut.v-1'>fn <a href='https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut' class='fnname'>borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#221-223' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></p>
|
||
</div></div><h3 id='impl-From%3CT%3E' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.From.html" title="trait nom::lib::std::prelude::v1::v1::From">From</a><T> for T</code><a href='#impl-From%3CT%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#564-568' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from-17' class="method hidden"><code id='from.v-17'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.From.html#tymethod.from' class='fnname'>from</a>(t: T) -> T</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#565-567' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-Into%3CU%3E' class='impl'><code class='in-band'>impl<T, U> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Into.html" title="trait nom::lib::std::prelude::v1::v1::Into">Into</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.From.html" title="trait nom::lib::std::prelude::v1::v1::From">From</a><T>, </span></code><a href='#impl-Into%3CU%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#553-560' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.into' class="method hidden"><code id='into.v'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.Into.html#tymethod.into' class='fnname'>into</a>(self) -> U</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#557-559' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-IntoIterator-3' class='impl'><code class='in-band'>impl<I> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html" title="trait nom::lib::std::prelude::v1::v1::IntoIterator">IntoIterator</a> for I <span class="where fmt-newline">where<br> I: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Iterator.html" title="trait nom::lib::std::prelude::v1::v1::Iterator">Iterator</a>, </span></code><a href='#impl-IntoIterator-3' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/iter/traits/collect.rs.html#243-250' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Item-3' class="type"><code id='Item.t-3'>type <a href='../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html#associatedtype.Item' class="type">Item</a> = <I as <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Iterator.html" title="trait nom::lib::std::prelude::v1::v1::Iterator">Iterator</a>>::<a class="type" href="../../../../nom/lib/std/prelude/v1/v1/trait.Iterator.html#associatedtype.Item" title="type nom::lib::std::prelude::v1::v1::Iterator::Item">Item</a></code></h4><div class='docblock'><p>The type of the elements being iterated over.</p>
|
||
</div><h4 id='associatedtype.IntoIter-3' class="type"><code id='IntoIter.t-3'>type <a href='../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html#associatedtype.IntoIter' class="type">IntoIter</a> = I</code></h4><div class='docblock'><p>Which kind of iterator are we turning this into?</p>
|
||
</div><h4 id='method.into_iter-3' class="method hidden"><code id='into_iter.v-3'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html#tymethod.into_iter' class='fnname'>into_iter</a>(self) -> I</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/iter/traits/collect.rs.html#247-249' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Creates an iterator from a value. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.IntoIterator.html#tymethod.into_iter">Read more</a></p>
|
||
</div></div><h3 id='impl-ToOwned' class='impl'><code class='in-band'>impl<T> <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.ToOwned.html" title="trait nom::lib::std::prelude::v1::v1::ToOwned">ToOwned</a> for T <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Clone.html" title="trait nom::lib::std::prelude::v1::v1::Clone">Clone</a>, </span></code><a href='#impl-ToOwned' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/borrow.rs.html#80-92' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Owned' class="type"><code id='Owned.t'>type <a href='../../../../nom/lib/std/prelude/v1/v1/trait.ToOwned.html#associatedtype.Owned' class="type">Owned</a> = T</code></h4><div class='docblock'><p>The resulting type after obtaining ownership.</p>
|
||
</div><h4 id='method.to_owned' class="method hidden"><code id='to_owned.v'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.ToOwned.html#tymethod.to_owned' class='fnname'>to_owned</a>(&self) -> T</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/borrow.rs.html#85-87' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Creates owned data from borrowed data, usually by cloning. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.ToOwned.html#tymethod.to_owned">Read more</a></p>
|
||
</div><h4 id='method.clone_into' class="method hidden"><code id='clone_into.v'>fn <a href='../../../../nom/lib/std/prelude/v1/v1/trait.ToOwned.html#method.clone_into' class='fnname'>clone_into</a>(&self, target: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T)</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/borrow.rs.html#89-91' title='goto source code'>[src]</a></h4><div class='stability hidden'><div class='stab unstable'><details><summary><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>toowned_clone_into</code>)</summary><p>recently added</p>
|
||
</details></div></div><div class='docblock hidden'><p>Uses borrowed data to replace owned data, usually by cloning. <a href="../../../../nom/lib/std/prelude/v1/v1/trait.ToOwned.html#method.clone_into">Read more</a></p>
|
||
</div></div><h3 id='impl-TryFrom%3CU%3E' class='impl'><code class='in-band'>impl<T, U> <a class="trait" href="../../../../nom/lib/std/convert/trait.TryFrom.html" title="trait nom::lib::std::convert::TryFrom">TryFrom</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Into.html" title="trait nom::lib::std::prelude::v1::v1::Into">Into</a><T>, </span></code><a href='#impl-TryFrom%3CU%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#601-610' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Error' class="type"><code id='Error.t'>type <a href='../../../../nom/lib/std/convert/trait.TryFrom.html#associatedtype.Error' class="type">Error</a> = <a class="enum" href="../../../../nom/lib/std/convert/enum.Infallible.html" title="enum nom::lib::std::convert::Infallible">Infallible</a></code></h4><div class='docblock'><p>The type returned in the event of a conversion error.</p>
|
||
</div><h4 id='method.try_from' class="method hidden"><code id='try_from.v'>fn <a href='../../../../nom/lib/std/convert/trait.TryFrom.html#tymethod.try_from' class='fnname'>try_from</a>(value: U) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Result.html" title="enum nom::lib::std::prelude::v1::v1::Result">Result</a><T, <T as <a class="trait" href="../../../../nom/lib/std/convert/trait.TryFrom.html" title="trait nom::lib::std::convert::TryFrom">TryFrom</a><U>>::<a class="type" href="../../../../nom/lib/std/convert/trait.TryFrom.html#associatedtype.Error" title="type nom::lib::std::convert::TryFrom::Error">Error</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#607-609' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-TryInto%3CU%3E' class='impl'><code class='in-band'>impl<T, U> <a class="trait" href="../../../../nom/lib/std/convert/trait.TryInto.html" title="trait nom::lib::std::convert::TryInto">TryInto</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="../../../../nom/lib/std/convert/trait.TryFrom.html" title="trait nom::lib::std::convert::TryFrom">TryFrom</a><T>, </span></code><a href='#impl-TryInto%3CU%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#587-596' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Error-1' class="type"><code id='Error.t-1'>type <a href='../../../../nom/lib/std/convert/trait.TryInto.html#associatedtype.Error' class="type">Error</a> = <U as <a class="trait" href="../../../../nom/lib/std/convert/trait.TryFrom.html" title="trait nom::lib::std::convert::TryFrom">TryFrom</a><T>>::<a class="type" href="../../../../nom/lib/std/convert/trait.TryFrom.html#associatedtype.Error" title="type nom::lib::std::convert::TryFrom::Error">Error</a></code></h4><div class='docblock'><p>The type returned in the event of a conversion error.</p>
|
||
</div><h4 id='method.try_into' class="method hidden"><code id='try_into.v'>fn <a href='../../../../nom/lib/std/convert/trait.TryInto.html#tymethod.try_into' class='fnname'>try_into</a>(self) -> <a class="enum" href="../../../../nom/lib/std/prelude/v1/v1/enum.Result.html" title="enum nom::lib::std::prelude::v1::v1::Result">Result</a><U, <U as <a class="trait" href="../../../../nom/lib/std/convert/trait.TryFrom.html" title="trait nom::lib::std::convert::TryFrom">TryFrom</a><T>>::<a class="type" href="../../../../nom/lib/std/convert/trait.TryFrom.html#associatedtype.Error" title="type nom::lib::std::convert::TryFrom::Error">Error</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#593-595' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div></div></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../../../../";window.currentCrate = "nom";</script><script src="../../../../aliases.js"></script><script src="../../../../main.js"></script><script defer src="../../../../search-index.js"></script></body></html> |