612 lines
125 KiB
HTML
612 lines
125 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 `AcceptLanguage` struct in crate `actix_web`."><meta name="keywords" content="rust, rustlang, rust-lang, AcceptLanguage"><title>actix_web::http::header::AcceptLanguage - 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='../../../actix_web/index.html'><div class='logo-container'><img src='../../../rust-logo.png' alt='logo'></div></a><p class='location'>Struct AcceptLanguage</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#deref-methods">Methods from Deref<Target=Vec<QualityItem<LanguageTag>>></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.insert">insert</a><a href="#method.is_empty">is_empty</a><a href="#method.len">len</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></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Clone">Clone</a><a href="#impl-Debug">Debug</a><a href="#impl-Deref">Deref</a><a href="#impl-DerefMut">DerefMut</a><a href="#impl-Display">Display</a><a href="#impl-Header">Header</a><a href="#impl-IntoHeaderValue">IntoHeaderValue</a><a href="#impl-PartialEq%3CAcceptLanguage%3E">PartialEq<AcceptLanguage></a><a href="#impl-StructuralPartialEq">StructuralPartialEq</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-ToOwned">ToOwned</a><a href="#impl-ToString">ToString</a><a href="#impl-TryFrom%3CU%3E">TryFrom<U></a><a href="#impl-TryInto%3CU%3E">TryInto<U></a><a href="#impl-VZip%3CV%3E">VZip<V></a></div></div><p class='location'><a href='../../index.html'>actix_web</a>::<wbr><a href='../index.html'>http</a>::<wbr><a href='index.html'>header</a></p><script>window.sidebarCurrent = {name: 'AcceptLanguage', 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 id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>−</span>]</a></span><a class='srclink' href='../../../src/actix_http/header/common/mod.rs.html#181' title='goto source code'>[src]</a></span><span class='in-band'>Struct <a href='../../index.html'>actix_web</a>::<wbr><a href='../index.html'>http</a>::<wbr><a href='index.html'>header</a>::<wbr><a class="struct" href=''>AcceptLanguage</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class='rust struct'>pub struct AcceptLanguage(pub <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="struct" href="../../../actix_web/http/header/struct.QualityItem.html" title="struct actix_web::http::header::QualityItem">QualityItem</a><<a class="struct" href="../../../actix_web/http/header/struct.LanguageTag.html" title="struct actix_web::http::header::LanguageTag">LanguageTag</a>>>);</pre></div><div class='docblock'><p><code>Accept-Language</code> header, defined in
|
||
<a href="http://tools.ietf.org/html/rfc7231#section-5.3.5">RFC7231</a></p>
|
||
<p>The <code>Accept-Language</code> header field can be used by user agents to
|
||
indicate the set of natural languages that are preferred in the
|
||
response.</p>
|
||
<h1 id="abnf" class="section-header"><a href="#abnf">ABNF</a></h1>
|
||
<pre><code class="language-text">Accept-Language = 1#( language-range [ weight ] )
|
||
language-range = <language-range, see [RFC4647], Section 2.1>
|
||
</code></pre>
|
||
<h1 id="example-values" class="section-header"><a href="#example-values">Example values</a></h1>
|
||
<ul>
|
||
<li><code>da, en-gb;q=0.8, en;q=0.7</code></li>
|
||
<li><code>en-us;q=1.0, en;q=0.5, fr</code></li>
|
||
</ul>
|
||
<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">use</span> <span class="ident">actix_http</span>::<span class="ident">Response</span>;
|
||
<span class="kw">use</span> <span class="ident">actix_http</span>::<span class="ident">http</span>::<span class="ident">header</span>::{<span class="ident">AcceptLanguage</span>, <span class="ident">LanguageTag</span>, <span class="ident">qitem</span>};
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">builder</span> <span class="op">=</span> <span class="ident">Response</span>::<span class="prelude-val">Ok</span>();
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">langtag</span>: <span class="ident">LanguageTag</span> <span class="op">=</span> <span class="ident">Default</span>::<span class="ident">default</span>();
|
||
<span class="ident">langtag</span>.<span class="ident">language</span> <span class="op">=</span> <span class="prelude-val">Some</span>(<span class="string">"en"</span>.<span class="ident">to_owned</span>());
|
||
<span class="ident">langtag</span>.<span class="ident">region</span> <span class="op">=</span> <span class="prelude-val">Some</span>(<span class="string">"US"</span>.<span class="ident">to_owned</span>());
|
||
<span class="ident">builder</span>.<span class="ident">set</span>(
|
||
<span class="ident">AcceptLanguage</span>(<span class="macro">vec</span><span class="macro">!</span>[
|
||
<span class="ident">qitem</span>(<span class="ident">langtag</span>),
|
||
])
|
||
);</pre></div>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">actix_http</span>::<span class="ident">Response</span>;
|
||
<span class="kw">use</span> <span class="ident">actix_http</span>::<span class="ident">http</span>::<span class="ident">header</span>::{<span class="ident">AcceptLanguage</span>, <span class="ident">QualityItem</span>, <span class="ident">q</span>, <span class="ident">qitem</span>};
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">builder</span> <span class="op">=</span> <span class="ident">Response</span>::<span class="prelude-val">Ok</span>();
|
||
<span class="ident">builder</span>.<span class="ident">set</span>(
|
||
<span class="ident">AcceptLanguage</span>(<span class="macro">vec</span><span class="macro">!</span>[
|
||
<span class="ident">qitem</span>(<span class="macro">langtag</span><span class="macro">!</span>(<span class="ident">da</span>)),
|
||
<span class="ident">QualityItem</span>::<span class="ident">new</span>(<span class="macro">langtag</span><span class="macro">!</span>(<span class="ident">en</span>;;;<span class="ident">GB</span>), <span class="ident">q</span>(<span class="number">800</span>)),
|
||
<span class="ident">QualityItem</span>::<span class="ident">new</span>(<span class="macro">langtag</span><span class="macro">!</span>(<span class="ident">en</span>), <span class="ident">q</span>(<span class="number">700</span>)),
|
||
])
|
||
);</pre></div>
|
||
</div><h2 id='deref-methods' class='small-section-header'>Methods from <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a><Target = <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="struct" href="../../../actix_web/http/header/struct.QualityItem.html" title="struct actix_web::http::header::QualityItem">QualityItem</a><<a class="struct" href="../../../actix_web/http/header/struct.LanguageTag.html" title="struct actix_web::http::header::LanguageTag">LanguageTag</a>>>><a href='#deref-methods' class='anchor'></a></h2><div class='impl-items'><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><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.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-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="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><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.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-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="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><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.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-3" class="section-header"><a href="#examples-3">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="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="enum" href="https://doc.rust-lang.org/nightly/alloc/collections/enum.TryReserveError.html" title="enum alloc::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-4" class="section-header"><a href="#examples-4">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="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="enum" href="https://doc.rust-lang.org/nightly/alloc/collections/enum.TryReserveError.html" title="enum alloc::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-5" class="section-header"><a href="#examples-5">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><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.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-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="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-7" class="section-header"><a href="#examples-7">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.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><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.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-8" class="section-header"><a href="#examples-8">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-9" class="section-header"><a href="#examples-9">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-10" class="section-header"><a href="#examples-10">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-11" class="section-header"><a href="#examples-11">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-12" class="section-header"><a href="#examples-12">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><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.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" class="section-header"><a href="#safety">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-13" class="section-header"><a href="#examples-13">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><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.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-14" class="section-header"><a href="#examples-14">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><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.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-15" class="section-header"><a href="#examples-15">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><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.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-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="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="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/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.0.0'>1.0.0</span><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-17" class="section-header"><a href="#examples-17">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="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T) -> K,<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html" title="trait core::cmp::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-18" class="section-header"><a href="#examples-18">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="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/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-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">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><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.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-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="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="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><T></code><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.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-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">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="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::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-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="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="https://doc.rust-lang.org/nightly/alloc/vec/struct.Drain.html" title="struct alloc::vec::Drain">Drain</a><T> <span class="where fmt-newline">where<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/range/trait.RangeBounds.html" title="trait core::ops::range::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-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">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><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.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-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">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><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.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-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="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><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.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-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">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="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::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-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="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="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::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-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">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></div><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-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">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-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="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><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-31" class="section-header"><a href="#examples-31">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><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><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/vec.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-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">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><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="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><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-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="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><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="https://doc.rust-lang.org/nightly/alloc/vec/struct.Splice.html" title="struct alloc::vec::Splice">Splice</a><<I as <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" title="type core::iter::traits::collect::IntoIterator::IntoIter">IntoIter</a>> <span class="where fmt-newline">where<br> I: <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a><Item = T>,<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/range/trait.RangeBounds.html" title="trait core::ops::range::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-34" class="section-header"><a href="#examples-34">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="https://doc.rust-lang.org/nightly/alloc/vec/struct.DrainFilter.html" title="struct alloc::vec::DrainFilter">DrainFilter</a><T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/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-35" class="section-header"><a href="#examples-35">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='implementations' class='small-section-header'>Trait Implementations<a href='#implementations' class='anchor'></a></h2><div id='implementations-list'><h3 id='impl-Clone' class='impl'><code class='in-band'>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="../../../actix_web/http/header/struct.AcceptLanguage.html" title="struct actix_web::http::header::AcceptLanguage">AcceptLanguage</a></code><a href='#impl-Clone' class='anchor'></a><a class='srclink' href='../../../src/actix_http/header/common/mod.rs.html#180' 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='https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone' class='fnname'>clone</a>(&self) -> <a class="struct" href="../../../actix_web/http/header/struct.AcceptLanguage.html" title="struct actix_web::http::header::AcceptLanguage">AcceptLanguage</a></code><a class='srclink' href='../../../src/actix_http/header/common/mod.rs.html#180' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Returns a copy of the value. <a href="https://doc.rust-lang.org/nightly/core/clone/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='https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from' class='fnname'>clone_from</a>(&mut self, source: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>Self)</code><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/clone.rs.html#131-133' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs copy-assignment from <code>source</code>. <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from">Read more</a></p>
|
||
</div></div><h3 id='impl-Debug' class='impl'><code class='in-band'>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="../../../actix_web/http/header/struct.AcceptLanguage.html" title="struct actix_web::http::header::AcceptLanguage">AcceptLanguage</a></code><a href='#impl-Debug' class='anchor'></a><a class='srclink' href='../../../src/actix_http/header/common/mod.rs.html#180' 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='https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&self, f: &mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Error.html" title="struct core::fmt::Error">Error</a>></code><a class='srclink' href='../../../src/actix_http/header/common/mod.rs.html#180' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
|
||
</div></div><h3 id='impl-Deref' class='impl'><code class='in-band'>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a> for <a class="struct" href="../../../actix_web/http/header/struct.AcceptLanguage.html" title="struct actix_web::http::header::AcceptLanguage">AcceptLanguage</a></code><a href='#impl-Deref' class='anchor'></a><a class='srclink' href='../../../src/actix_http/header/common/mod.rs.html#35-42' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Target' class="type"><code id='Target.t'>type <a href='https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html#associatedtype.Target' class="type">Target</a> = <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="struct" href="../../../actix_web/http/header/struct.QualityItem.html" title="struct actix_web::http::header::QualityItem">QualityItem</a><<a class="struct" href="../../../actix_web/http/header/struct.LanguageTag.html" title="struct actix_web::http::header::LanguageTag">LanguageTag</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='https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html#tymethod.deref' class='fnname'>deref</a>(&self) -> &<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="struct" href="../../../actix_web/http/header/struct.QualityItem.html" title="struct actix_web::http::header::QualityItem">QualityItem</a><<a class="struct" href="../../../actix_web/http/header/struct.LanguageTag.html" title="struct actix_web::http::header::LanguageTag">LanguageTag</a>>></code><a class='srclink' href='../../../src/actix_http/header/common/mod.rs.html#39-41' 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 <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.DerefMut.html" title="trait core::ops::deref::DerefMut">DerefMut</a> for <a class="struct" href="../../../actix_web/http/header/struct.AcceptLanguage.html" title="struct actix_web::http::header::AcceptLanguage">AcceptLanguage</a></code><a href='#impl-DerefMut' class='anchor'></a><a class='srclink' href='../../../src/actix_http/header/common/mod.rs.html#44-49' 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='https://doc.rust-lang.org/nightly/core/ops/deref/trait.DerefMut.html#tymethod.deref_mut' class='fnname'>deref_mut</a>(&mut self) -> &mut <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="struct" href="../../../actix_web/http/header/struct.QualityItem.html" title="struct actix_web::http::header::QualityItem">QualityItem</a><<a class="struct" href="../../../actix_web/http/header/struct.LanguageTag.html" title="struct actix_web::http::header::LanguageTag">LanguageTag</a>>></code><a class='srclink' href='../../../src/actix_http/header/common/mod.rs.html#46-48' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Mutably dereferences the value.</p>
|
||
</div></div><h3 id='impl-Display' class='impl'><code class='in-band'>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a> for <a class="struct" href="../../../actix_web/http/header/struct.AcceptLanguage.html" title="struct actix_web::http::header::AcceptLanguage">AcceptLanguage</a></code><a href='#impl-Display' class='anchor'></a><a class='srclink' href='../../../src/actix_http/header/common/mod.rs.html#196-201' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.fmt-1' class="method hidden"><code id='fmt.v-1'>fn <a href='https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html#tymethod.fmt' class='fnname'>fmt</a>(&self, f: &mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Error.html" title="struct core::fmt::Error">Error</a>></code><a class='srclink' href='../../../src/actix_http/header/common/mod.rs.html#198-200' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html#tymethod.fmt">Read more</a></p>
|
||
</div></div><h3 id='impl-Header' class='impl'><code class='in-band'>impl <a class="trait" href="../../../actix_web/http/header/trait.Header.html" title="trait actix_web::http::header::Header">Header</a> for <a class="struct" href="../../../actix_web/http/header/struct.AcceptLanguage.html" title="struct actix_web::http::header::AcceptLanguage">AcceptLanguage</a></code><a href='#impl-Header' class='anchor'></a><a class='srclink' href='../../../src/actix_http/header/common/mod.rs.html#183-195' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.name' class="method hidden"><code id='name.v'>fn <a href='../../../actix_web/http/header/trait.Header.html#tymethod.name' class='fnname'>name</a>() -> <a class="struct" href="../../../actix_web/http/struct.HeaderName.html" title="struct actix_web::http::HeaderName">HeaderName</a></code><a class='srclink' href='../../../src/actix_http/header/common/mod.rs.html#185-187' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Returns the name of the header field</p>
|
||
</div><h4 id='method.parse' class="method hidden"><code id='parse.v'>fn <a href='../../../actix_web/http/header/trait.Header.html#tymethod.parse' class='fnname'>parse</a><T>(msg: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../../../actix_web/http/header/struct.AcceptLanguage.html" title="struct actix_web::http::header::AcceptLanguage">AcceptLanguage</a>, <a class="enum" href="../../../actix_web/error/enum.ParseError.html" title="enum actix_web::error::ParseError">ParseError</a>> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../../actix_web/trait.HttpMessage.html" title="trait actix_web::HttpMessage">HttpMessage</a>, </span></code><a class='srclink' href='../../../src/actix_http/header/common/mod.rs.html#189-194' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Parse a header</p>
|
||
</div></div><h3 id='impl-IntoHeaderValue' class='impl'><code class='in-band'>impl <a class="trait" href="../../../actix_web/http/header/trait.IntoHeaderValue.html" title="trait actix_web::http::header::IntoHeaderValue">IntoHeaderValue</a> for <a class="struct" href="../../../actix_web/http/header/struct.AcceptLanguage.html" title="struct actix_web::http::header::AcceptLanguage">AcceptLanguage</a></code><a href='#impl-IntoHeaderValue' class='anchor'></a><a class='srclink' href='../../../src/actix_http/header/common/mod.rs.html#202-211' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Error' class="type"><code id='Error.t'>type <a href='../../../actix_web/http/header/trait.IntoHeaderValue.html#associatedtype.Error' class="type">Error</a> = <a class="struct" href="../../../actix_web/http/header/struct.InvalidHeaderValueBytes.html" title="struct actix_web::http::header::InvalidHeaderValueBytes">InvalidHeaderValueBytes</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='../../../actix_web/http/header/trait.IntoHeaderValue.html#tymethod.try_into' class='fnname'>try_into</a>(<br> self<br>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="../../../actix_web/http/struct.HeaderValue.html" title="struct actix_web::http::HeaderValue">HeaderValue</a>, <<a class="struct" href="../../../actix_web/http/header/struct.AcceptLanguage.html" title="struct actix_web::http::header::AcceptLanguage">AcceptLanguage</a> as <a class="trait" href="../../../actix_web/http/header/trait.IntoHeaderValue.html" title="trait actix_web::http::header::IntoHeaderValue">IntoHeaderValue</a>>::<a class="type" href="../../../actix_web/http/header/trait.IntoHeaderValue.html#associatedtype.Error" title="type actix_web::http::header::IntoHeaderValue::Error">Error</a>></code><a class='srclink' href='../../../src/actix_http/header/common/mod.rs.html#205-210' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Try to convert value to a Header value.</p>
|
||
</div></div><h3 id='impl-PartialEq%3CAcceptLanguage%3E' class='impl'><code class='in-band'>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><<a class="struct" href="../../../actix_web/http/header/struct.AcceptLanguage.html" title="struct actix_web::http::header::AcceptLanguage">AcceptLanguage</a>> for <a class="struct" href="../../../actix_web/http/header/struct.AcceptLanguage.html" title="struct actix_web::http::header::AcceptLanguage">AcceptLanguage</a></code><a href='#impl-PartialEq%3CAcceptLanguage%3E' class='anchor'></a><a class='srclink' href='../../../src/actix_http/header/common/mod.rs.html#180' 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='https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&self, other: &<a class="struct" href="../../../actix_web/http/header/struct.AcceptLanguage.html" title="struct actix_web::http::header::AcceptLanguage">AcceptLanguage</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='../../../src/actix_http/header/common/mod.rs.html#180' 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="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p>
|
||
</div><h4 id='method.ne' class="method hidden"><code id='ne.v'>fn <a href='https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&self, other: &<a class="struct" href="../../../actix_web/http/header/struct.AcceptLanguage.html" title="struct actix_web::http::header::AcceptLanguage">AcceptLanguage</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='../../../src/actix_http/header/common/mod.rs.html#180' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>!=</code>.</p>
|
||
</div></div><h3 id='impl-StructuralPartialEq' class='impl'><code class='in-band'>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.StructuralPartialEq.html" title="trait core::marker::StructuralPartialEq">StructuralPartialEq</a> for <a class="struct" href="../../../actix_web/http/header/struct.AcceptLanguage.html" title="struct actix_web::http::header::AcceptLanguage">AcceptLanguage</a></code><a href='#impl-StructuralPartialEq' class='anchor'></a><a class='srclink' href='../../../src/actix_http/header/common/mod.rs.html#180' title='goto source code'>[src]</a></h3><div class='impl-items'></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 <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="../../../actix_web/http/header/struct.AcceptLanguage.html" title="struct actix_web::http::header::AcceptLanguage">AcceptLanguage</a></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 <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="../../../actix_web/http/header/struct.AcceptLanguage.html" title="struct actix_web::http::header::AcceptLanguage">AcceptLanguage</a></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 <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="../../../actix_web/http/header/struct.AcceptLanguage.html" title="struct actix_web::http::header::AcceptLanguage">AcceptLanguage</a></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 <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="../../../actix_web/http/header/struct.AcceptLanguage.html" title="struct actix_web::http::header::AcceptLanguage">AcceptLanguage</a></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 <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="../../../actix_web/http/header/struct.AcceptLanguage.html" title="struct actix_web::http::header::AcceptLanguage">AcceptLanguage</a></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="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::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="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::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' 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.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="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::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' 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.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="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::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' class="method hidden"><code id='from.v'>fn <a href='https://doc.rust-lang.org/nightly/core/convert/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="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><T>, </span></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='https://doc.rust-lang.org/nightly/core/convert/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-ToOwned' class='impl'><code class='in-band'>impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html" title="trait alloc::borrow::ToOwned">ToOwned</a> for T <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::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='https://doc.rust-lang.org/nightly/alloc/borrow/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='https://doc.rust-lang.org/nightly/alloc/borrow/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="https://doc.rust-lang.org/nightly/alloc/borrow/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='https://doc.rust-lang.org/nightly/alloc/borrow/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="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#method.clone_into">Read more</a></p>
|
||
</div></div><h3 id='impl-ToString' class='impl'><code class='in-band'>impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/alloc/string/trait.ToString.html" title="trait alloc::string::ToString">ToString</a> for T <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a href='#impl-ToString' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/string.rs.html#2160-2170' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.to_string' class="method hidden"><code id='to_string.v'>default fn <a href='https://doc.rust-lang.org/nightly/alloc/string/trait.ToString.html#tymethod.to_string' class='fnname'>to_string</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/string.rs.html#2162-2169' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Converts the given value to a <code>String</code>. <a href="https://doc.rust-lang.org/nightly/alloc/string/trait.ToString.html#tymethod.to_string">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="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>, </span></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-1' class="type"><code id='Error.t-1'>type <a href='https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error' class="type">Error</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/convert/enum.Infallible.html" title="enum core::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='https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#tymethod.try_from' class='fnname'>try_from</a>(value: U) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <T as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::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="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>, </span></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-2' class="type"><code id='Error.t-2'>type <a href='https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#associatedtype.Error' class="type">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::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-1' class="method hidden"><code id='try_into.v-1'>fn <a href='https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#tymethod.try_into' class='fnname'>try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, <U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::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><h3 id='impl-VZip%3CV%3E' class='impl'><code class='in-band'>impl<V, T> <a class="trait" href="../../../ppv_lite86/types/types/trait.VZip.html" title="trait ppv_lite86::types::types::VZip">VZip</a><V> for T <span class="where fmt-newline">where<br> V: <a class="trait" href="../../../ppv_lite86/types/types/trait.MultiLane.html" title="trait ppv_lite86::types::types::MultiLane">MultiLane</a><T>, </span></code><a href='#impl-VZip%3CV%3E' class='anchor'></a><a class='srclink' href='../../../src/ppv_lite86/types.rs.html#212-220' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.vzip' class="method hidden"><code id='vzip.v'>fn <a href='../../../ppv_lite86/types/types/trait.VZip.html#tymethod.vzip' class='fnname'>vzip</a>(self) -> V</code><a class='srclink' href='../../../src/ppv_lite86/types.rs.html#217-219' title='goto source code'>[src]</a></h4></div></div></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../../../";window.currentCrate = "actix_web";</script><script src="../../../aliases.js"></script><script src="../../../main.js"></script><script defer src="../../../search-index.js"></script></body></html> |