blob: a4d9249b15b9b96ea8b8d163d394356e0145b4c8 [file] [log] [blame]
<!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="Small vectors in various sizes. These store a certain number of elements inline, and fall back to the heap for larger allocations. This can be a useful optimization for improving cache locality and reducing allocator traffic for workloads that fit within the inline buffer."><meta name="keywords" content="rust, rustlang, rust-lang, smallvec"><title>smallvec - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../normalize.css"><link rel="stylesheet" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../ayu.css" disabled><link rel="stylesheet" href="../dark.css" disabled><link rel="stylesheet" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="../crates.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../smallvec/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../smallvec/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Crate smallvec</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 1.10.0</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#macros">Macros</a></li><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#traits">Traits</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Crate <a class="mod" href="#">smallvec</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/smallvec/lib.rs.html#7-2132">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Small vectors in various sizes. These store a certain number of elements inline, and fall back
to the heap for larger allocations. This can be a useful optimization for improving cache
locality and reducing allocator traffic for workloads that fit within the inline buffer.</p>
<h3 id="no_std-support"><a href="#no_std-support"><code>no_std</code> support</a></h3>
<p>By default, <code>smallvec</code> does not depend on <code>std</code>. However, the optional
<code>write</code> feature implements the <code>std::io::Write</code> trait for vectors of <code>u8</code>.
When this feature is enabled, <code>smallvec</code> depends on <code>std</code>.</p>
<h3 id="optional-features"><a href="#optional-features">Optional features</a></h3><h4 id="serde"><a href="#serde"><code>serde</code></a></h4>
<p>When this optional dependency is enabled, <code>SmallVec</code> implements the <code>serde::Serialize</code> and
<code>serde::Deserialize</code> traits.</p>
<h4 id="write"><a href="#write"><code>write</code></a></h4>
<p>When this feature is enabled, <code>SmallVec&lt;[u8; _]&gt;</code> implements the <code>std::io::Write</code> trait.
This feature is not compatible with <code>#![no_std]</code> programs.</p>
<h4 id="union"><a href="#union"><code>union</code></a></h4>
<p><strong>This feature requires Rust 1.49.</strong></p>
<p>When the <code>union</code> feature is enabled <code>smallvec</code> will track its state (inline or spilled)
without the use of an enum tag, reducing the size of the <code>smallvec</code> by one machine word.
This means that there is potentially no space overhead compared to <code>Vec</code>.
Note that <code>smallvec</code> can still be larger than <code>Vec</code> if the inline buffer is larger than two
machine words.</p>
<p>To use this feature add <code>features = [&quot;union&quot;]</code> in the <code>smallvec</code> section of Cargo.toml.
Note that this feature requires Rust 1.49.</p>
<p>Tracking issue: <a href="https://github.com/rust-lang/rust/issues/55149">rust-lang/rust#55149</a></p>
<h4 id="const_generics"><a href="#const_generics"><code>const_generics</code></a></h4>
<p><strong>This feature requires Rust 1.51.</strong></p>
<p>When this feature is enabled, <code>SmallVec</code> works with any arrays of any size, not just a fixed
list of sizes.</p>
<h4 id="const_new"><a href="#const_new"><code>const_new</code></a></h4>
<p><strong>This feature requires Rust 1.51.</strong></p>
<p>This feature exposes the functions [<code>SmallVec::new_const</code>], [<code>SmallVec::from_const</code>], and [<code>smallvec_inline</code>] which enables the <code>SmallVec</code> to be initialized from a const context.
For details, see the
<a href="https://doc.rust-lang.org/reference/const_eval.html#const-functions">Rust Reference</a>.</p>
<h4 id="specialization"><a href="#specialization"><code>specialization</code></a></h4>
<p><strong>This feature is unstable and requires a nightly build of the Rust toolchain.</strong></p>
<p>When this feature is enabled, <code>SmallVec::from(slice)</code> has improved performance for slices
of <code>Copy</code> types. (Without this feature, you can use <code>SmallVec::from_slice</code> to get optimal
performance for <code>Copy</code> types.)</p>
<p>Tracking issue: <a href="https://github.com/rust-lang/rust/issues/31844">rust-lang/rust#31844</a></p>
<h4 id="may_dangle"><a href="#may_dangle"><code>may_dangle</code></a></h4>
<p><strong>This feature is unstable and requires a nightly build of the Rust toolchain.</strong></p>
<p>This feature makes the Rust compiler less strict about use of vectors that contain borrowed
references. For details, see the
<a href="https://doc.rust-lang.org/1.42.0/nomicon/dropck.html#an-escape-hatch">Rustonomicon</a>.</p>
<p>Tracking issue: <a href="https://github.com/rust-lang/rust/issues/34761">rust-lang/rust#34761</a></p>
</div></details><h2 id="macros" class="small-section-header"><a href="#macros">Macros</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.smallvec.html" title="smallvec::smallvec macro">smallvec</a></div><div class="item-right docblock-short">Creates a <a href="struct.SmallVec.html" title="SmallVec"><code>SmallVec</code></a> containing the arguments.</div></div></div><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Drain.html" title="smallvec::Drain struct">Drain</a></div><div class="item-right docblock-short">An iterator that removes the items from a <code>SmallVec</code> and yields them by value.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.IntoIter.html" title="smallvec::IntoIter struct">IntoIter</a></div><div class="item-right docblock-short">An iterator that consumes a <code>SmallVec</code> and yields its items by value.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.SmallVec.html" title="smallvec::SmallVec struct">SmallVec</a></div><div class="item-right docblock-short">A <code>Vec</code>-like container that can store a small number of elements inline.</div></div></div><h2 id="enums" class="small-section-header"><a href="#enums">Enums</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.CollectionAllocErr.html" title="smallvec::CollectionAllocErr enum">CollectionAllocErr</a></div><div class="item-right docblock-short">Error type for APIs with fallible heap allocation</div></div></div><h2 id="traits" class="small-section-header"><a href="#traits">Traits</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Array.html" title="smallvec::Array trait">Array</a></div><div class="item-right docblock-short">Types that can be used as the backing store for a SmallVec</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.ToSmallVec.html" title="smallvec::ToSmallVec trait">ToSmallVec</a></div><div class="item-right docblock-short">Convenience trait for constructing a <code>SmallVec</code></div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="smallvec" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>