Rust-for-Arduboy/docs/doc/heapless/index.html

64 lines
14 KiB
HTML
Raw Normal View History

2023-08-23 08:44:29 +02:00
<!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="`static` friendly data structures that dont require dynamic memory allocation"><title>heapless - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-cb6f1f67f1bcd037.css" id="mainThemeStyle"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="heapless" data-themes="" data-resource-suffix="" data-rustdoc-version="1.73.0-nightly (8131b9774 2023-08-02)" data-channel="nightly" data-search-js="search-6dfdfced5eff6596.js" data-settings-js="settings-de11bff964e9d4e5.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-6d2c9675f3d09c26.css" data-theme-dark-css="dark-45ceb8f2e522f4d1.css" data-theme-ayu-css="ayu-fd19013d6ce078bf.css" ><script src="../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-0795b7d26be81095.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../static.files/light-6d2c9675f3d09c26.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../static.files/dark-45ceb8f2e522f4d1.css"><link rel="stylesheet" href="../static.files/noscript-cffde32267a19fd6.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.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="logo-container" href="../heapless/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2></h2></nav><nav class="sidebar"><a class="logo-container" href="../heapless/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2 class="location"><a href="#">Crate heapless</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 0.7.16</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#reexports">Re-exports</a></li><li><a href="#modules">Modules</a></li><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#types">Type Definitions</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" 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"
<p>The core principle behind <code>heapless</code> is that its data structures are backed by a <em>static</em> memory
allocation. For example, you can think of <code>heapless::Vec</code> as an alternative version of
<code>std::Vec</code> with fixed capacity and that cant be re-allocated on the fly (e.g. via <code>push</code>).</p>
<p>All <code>heapless</code> data structures store their memory allocation <em>inline</em> and specify their capacity
via their type parameter <code>N</code>. This means that you can instantiate a <code>heapless</code> data structure on
the stack, in a <code>static</code> variable, or even in the heap.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>heapless::Vec; <span class="comment">// fixed capacity `std::Vec`
// on the stack
</span><span class="kw">let </span><span class="kw-2">mut </span>xs: Vec&lt;u8, <span class="number">8</span>&gt; = Vec::new(); <span class="comment">// can hold up to 8 elements
</span>xs.push(<span class="number">42</span>).unwrap();
<span class="macro">assert_eq!</span>(xs.pop(), <span class="prelude-val">Some</span>(<span class="number">42</span>));
<span class="comment">// in a `static` variable
</span><span class="kw">static </span><span class="kw-2">mut </span>XS: Vec&lt;u8, <span class="number">8</span>&gt; = Vec::new();
<span class="kw">let </span>xs = <span class="kw">unsafe </span>{ <span class="kw-2">&amp;mut </span>XS };
xs.push(<span class="number">42</span>);
<span class="macro">assert_eq!</span>(xs.pop(), <span class="prelude-val">Some</span>(<span class="number">42</span>));
<span class="comment">// in the heap (though kind of pointless because no reallocation)
</span><span class="kw">let </span><span class="kw-2">mut </span>ys: Box&lt;Vec&lt;u8, <span class="number">8</span>&gt;&gt; = Box::new(Vec::new());
ys.push(<span class="number">42</span>).unwrap();
<span class="macro">assert_eq!</span>(ys.pop(), <span class="prelude-val">Some</span>(<span class="number">42</span>));</code></pre></div>
<p>Because they have fixed capacity <code>heapless</code> data structures dont implicitly reallocate. This
means that operations like <code>heapless::Vec.push</code> are <em>truly</em> constant time rather than amortized
constant time with potentially unbounded (depends on the allocator) worst case execution time
(which is bad / unacceptable for hard real time applications).</p>
<p><code>heapless</code> data structures dont use a memory allocator which means no risk of an uncatchable
Out Of Memory (OOM) condition while performing operations on them. Its certainly possible to
run out of capacity while growing <code>heapless</code> data structures, but the API lets you handle this
possibility by returning a <code>Result</code> on operations that may exhaust the capacity of the data
structure.</p>
<p>List of currently implemented data structures:</p>
<ul>
<li><a href="pool/singleton/arc/struct.Arc.html"><code>Arc</code></a> Thread-safe reference-counting pointer backed by a memory pool</li>
<li><a href="binary_heap/struct.BinaryHeap.html"><code>BinaryHeap</code></a> priority queue</li>
<li><a href="struct.IndexMap.html"><code>IndexMap</code></a> hash table</li>
<li><a href="struct.IndexSet.html"><code>IndexSet</code></a> hash set</li>
<li><a href="struct.LinearMap.html"><code>LinearMap</code></a></li>
<li><a href="pool/struct.Pool.html"><code>Pool</code></a> lock-free memory pool</li>
<li><a href="struct.String.html"><code>String</code></a></li>
<li><a href="struct.Vec.html"><code>Vec</code></a></li>
<li><a href="mpmc/index.html"><code>mpmc::Q*</code></a> multiple producer multiple consumer lock-free queue</li>
<li><a href="spsc/struct.Queue.html"><code>spsc::Queue</code></a> single producer single consumer lock-free queue</li>
</ul>
<h2 id="optional-features"><a href="#optional-features">Optional Features</a></h2>
<p>The <code>heapless</code> crate provides the following optional Cargo features:</p>
<ul>
<li><code>ufmt-impl</code>: Implement <a href="https://docs.rs/ufmt-write/"><code>ufmt_write::uWrite</code></a> for <code>String&lt;N&gt;</code> and <code>Vec&lt;u8, N&gt;</code></li>
</ul>
<h2 id="minimum-supported-rust-version-msrv"><a href="#minimum-supported-rust-version-msrv">Minimum Supported Rust Version (MSRV)</a></h2>
<p>This crate is guaranteed to compile on stable Rust 1.51 and up with its default set of features.
It <em>might</em> compile on older versions but that may change in any new patch release.</p>
</div></details><h2 id="reexports" class="small-section-header"><a href="#reexports">Re-exports</a></h2><ul class="item-table"><li><div class="item-name" id="reexport.BinaryHeap"><code>pub use binary_heap::<a class="struct" href="binary_heap/struct.BinaryHeap.html" title="struct heapless::binary_heap::BinaryHeap">BinaryHeap</a>;</code></div></li><li><div class="item-name" id="reexport.Bucket"><code>pub use indexmap::Bucket;</code></div></li><li><div class="item-name" id="reexport.Pos"><code>pub use indexmap::Pos;</code></div></li></ul><h2 id="modules" class="small-section-header"><a href="#modules">Modules</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="binary_heap/index.html" title="mod heapless::binary_heap">binary_heap</a></div><div class="desc docblock-short">A priority queue implemented with a binary heap.</div></li><li><div class="item-name"><a class="mod" href="sorted_linked_list/index.html" title="mod heapless::sorted_linked_list">sorted_linked_list</a></div><div class="desc docblock-short">A fixed sorted priority linked list, similar to <a href="binary_heap/struct.BinaryHeap.html" title="struct heapless::binary_heap::BinaryHeap"><code>BinaryHeap</code></a> but with different properties
on <code>push</code>, <code>pop</code>, etc.
For example, the sorting of the list will never <code>memcpy</code> the underlying value, so having large
objects in the list will not cause a performance hit.</div></li></ul><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Deque.html" title="struct heapless::Deque">Deque</a></div><div class="desc docblock-short">A fixed capacity double-ended queue.</div></li><li><div class="item-name"><a class="struct" href="struct.HistoryBuffer.html" title="struct heapless::HistoryBuffer">HistoryBuffer</a></div><div class="desc docblock-short">A “history buffer”, similar to a write-only ring buffer of fixed length.</div></li><li><div class="item-name"><a class="struct" href="struct.IndexMap.html" title="struct heapless::IndexMap">IndexMap</a></div><div class="desc docblock-short">Fixed capacity <a href="https://docs.rs/indexmap/1/indexmap/map/struct.IndexMap.html"><code>IndexMap</code></a></div></li><li><div class="item-name"><a class="struct" href="struct.IndexSet.html" title="struct heapless::IndexSet">IndexSet</a></div><div class="desc docblock-short">Fixed capacity <a href="https://docs.rs/indexmap/1/indexmap/set/struct.IndexSet.html"><code>IndexSet</code></a>.</div></li><li><div class="item-name"><a class="struct" href="struct.LinearMap.html" title="struct heapless::LinearMap">LinearMap</a></div><div class="desc docblock-short">A fixed capacity map / dictionary that performs lookups via linear search</div></li><li><div class="item-name"><a class="struct" href="struct.OccupiedEntry.html" title="struct heapless::OccupiedEntry">OccupiedEntry</a></div><div class="desc docblock-short">An occupied entry which can be manipulated</div></li><li><div class="item-name"><a class="struct" href="struct.OldestOrdered.html" title="struct heapless::OldestOrdered">OldestOrdered</a></div><div class="desc docblock-short">An iterator on the underlying buffer ordered from oldest data to newest</div></li><li><div class="item-name"><a class="struct" href="struct.String.html" title="struct heapless::String">String</a></div><div class="desc docblock-short">A fixed capacity <a href="https://doc.rust-lang.org/std/string/struct.String.html"><code>String</code></a></div></li><li><div class="item-name"><a class="struct" href="struct.VacantEntry.html" title="struct heapless::VacantEntry">VacantEntry</a></div><div class="desc docblock-short">A view into an empty slot in the underlying map</div></li><li><div class="item-name"><a class="struct" href="struct.Vec.html" title="struct heapless::Vec">Vec</a></div><div class="desc docblock-short">A fixed capacity <a href="https://doc.rust-lang.org/std/vec/struct.Vec.html"><code>Vec</code></a></div></li></ul><h2 id="enums" class="small-section-header"><a href="#enums">Enums</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.Entry.html" title="enum heapless::Entry">Entry</a></div><div class="desc docblock-short">A view into an entry in the map</div></li></ul><h2 id="types" class="small-section-header"><a href="#types">Type Definitions</a></h2><ul class="item-table"><li><div class="item-name"><a class="type" href="type.FnvIndexMap.html" title="type heapless::FnvIndexMap">FnvIndexMap</a></div><div class="desc docblock-short">A <a href="./struct.IndexMap.html"><code>heapless::IndexMap</code></a> using the default FNV hasher</div></li><li><div class="item-name"><a class="type" href="type.FnvIndexSet.html" title="type heapless::FnvIndexSet">FnvIndexSet</a></div><div class="desc docblock-short">A <a href="./struct.IndexSet.html"><code>heapless::IndexSet</code></a> using the
default FNV hasher.
A list of all Methods and Traits available for <code>FnvIndexSet</code> can be found in
the <a href="./struct.IndexSet.html"><code>heapless::IndexSet</code></a> documentation.</div></li></ul></section></div></main></body></html>