blob: 09668b0fd5f64da6a7269e79fa374153f93c3587 [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="Map is a lexicographically ordered map from byte strings to integers."><meta name="keywords" content="rust, rustlang, rust-lang, Map"><title>Map in tantivy_fst - 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="sidebar-items.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc struct"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../tantivy_fst/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="../tantivy_fst/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Map</a></h2><div class="sidebar-elems"><section><h3><a href="#implementations">Methods</a></h3><ul class="block"><li><a href="#method.as_fst">as_fst</a></li><li><a href="#method.contains_key">contains_key</a></li><li><a href="#method.from_bytes">from_bytes</a></li><li><a href="#method.from_iter">from_iter</a></li><li><a href="#method.get">get</a></li><li><a href="#method.is_empty">is_empty</a></li><li><a href="#method.keys">keys</a></li><li><a href="#method.len">len</a></li><li><a href="#method.op">op</a></li><li><a href="#method.range">range</a></li><li><a href="#method.search">search</a></li><li><a href="#method.stream">stream</a></li><li><a href="#method.values">values</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block"><li><a href="#impl-AsRef%3CFst%3CData%3E%3E-for-Map%3CData%3E">AsRef&lt;Fst&lt;Data&gt;&gt;</a></li><li><a href="#impl-Debug-for-Map%3CData%3E">Debug</a></li><li><a href="#impl-From%3CFst%3CData%3E%3E-for-Map%3CData%3E">From&lt;Fst&lt;Data&gt;&gt;</a></li><li><a href="#impl-IntoStreamer%3C%27a%3E-for-%26%27m%20Map%3CData%3E">IntoStreamer&lt;&#39;a&gt;</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block"><li><a href="#impl-RefUnwindSafe-for-Map%3CData%3E">RefUnwindSafe</a></li><li><a href="#impl-Send-for-Map%3CData%3E">Send</a></li><li><a href="#impl-Sync-for-Map%3CData%3E">Sync</a></li><li><a href="#impl-Unpin-for-Map%3CData%3E">Unpin</a></li><li><a href="#impl-UnwindSafe-for-Map%3CData%3E">UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block"><li><a href="#impl-Any-for-Map%3CData%3E">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-Map%3CData%3E">Borrow&lt;T&gt;</a></li><li><a href="#impl-BorrowMut%3CT%3E-for-Map%3CData%3E">BorrowMut&lt;T&gt;</a></li><li><a href="#impl-From%3CT%3E-for-Map%3CData%3E">From&lt;T&gt;</a></li><li><a href="#impl-Into%3CU%3E-for-Map%3CData%3E">Into&lt;U&gt;</a></li><li><a href="#impl-TryFrom%3CU%3E-for-Map%3CData%3E">TryFrom&lt;U&gt;</a></li><li><a href="#impl-TryInto%3CU%3E-for-Map%3CData%3E">TryInto&lt;U&gt;</a></li></ul></section><h2><a href="index.html">In tantivy_fst</a></h2></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">Struct <a href="index.html">tantivy_fst</a>::<wbr><a class="struct" href="#">Map</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/tantivy_fst/map.rs.html#57">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="item-decl"><pre class="rust struct"><code>pub struct Map&lt;Data&gt;(_);</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Map is a lexicographically ordered map from byte strings to integers.</p>
<p>A <code>Map</code> is constructed with the <code>MapBuilder</code> type. Alternatively, a <code>Map</code>
can be constructed in memory from a lexicographically ordered iterator
of key-value pairs (<code>Map::from_iter</code>).</p>
<p>A key feature of <code>Map</code> is that it can be serialized to disk compactly. Its
underlying representation is built such that the <code>Map</code> can be memory mapped
(<code>Map::from_path</code>) and searched without necessarily loading the entire
map into memory.</p>
<p>It supports most common operations associated with maps, such as key
lookup and search. It also supports set operations on its keys along with
the ability to specify how conflicting values are merged together. Maps
also support range queries and automata based searches (e.g. a regular
expression).</p>
<p>Maps are represented by a finite state transducer where inputs are the keys
and outputs are the values. As such, maps have the following invariants:</p>
<ol>
<li>Once constructed, a <code>Map</code> can never be modified.</li>
<li>Maps must be constructed with lexicographically ordered byte sequences.
There is no restricting on the ordering of values.</li>
</ol>
<h2 id="differences-with-sets"><a href="#differences-with-sets">Differences with sets</a></h2>
<p>Maps and sets are represented by the same underlying data structure: the
finite state transducer. The principal difference between them is that
sets always have their output values set to <code>0</code>. This has an impact on the
representation size and is reflected in the type system for convenience.
A secondary but subtle difference is that duplicate values can be added
to a set, but it is an error to do so with maps. That is, a set can have
the same key added sequentially, but a map can’t.</p>
<h2 id="the-future"><a href="#the-future">The future</a></h2>
<p>It is regrettable that the output value is fixed to <code>u64</code>. Indeed, it is
not necessary, but it was a major simplification in the implementation.
In the future, the value type may become generic to an extent (outputs must
satisfy a basic algebra).</p>
<p>Keys will always be byte strings; however, we may grow more conveniences
around dealing with them (such as a serialization/deserialization step,
although it isn’t clear where exactly this should live).</p>
</div></details><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><div id="implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Map%3CVec%3Cu8%3E%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#59-90">source</a><a href="#impl-Map%3CVec%3Cu8%3E%3E" class="anchor"></a><h3 class="code-header">impl <a class="struct" href="map/struct.Map.html" title="struct tantivy_fst::map::Map">Map</a>&lt;Vec&lt;u8&gt;&gt;</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_bytes" class="method has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#68-70">source</a><h4 class="code-header">pub fn <a href="#method.from_bytes" class="fnname">from_bytes</a>(bytes: Vec&lt;u8&gt;) -&gt; <a class="type" href="type.Result.html" title="type tantivy_fst::Result">Result</a>&lt;<a class="struct" href="map/struct.Map.html" title="struct tantivy_fst::map::Map">Map</a>&lt;Vec&lt;u8&gt;&gt;&gt;</h4></section></summary><div class="docblock"><p>Creates a map from its representation as a raw byte sequence.</p>
<p>Note that this operation is very cheap (no allocations and no copies).</p>
<p>The map must have been written with a compatible finite state
transducer builder (<code>MapBuilder</code> qualifies). If the format is invalid
or if there is a mismatch between the API version of this library
and the map, then an error is returned.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_iter" class="method has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#81-89">source</a><h4 class="code-header">pub fn <a href="#method.from_iter" class="fnname">from_iter</a>&lt;K, I&gt;(iter: I) -&gt; <a class="type" href="type.Result.html" title="type tantivy_fst::Result">Result</a>&lt;Self&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;K: AsRef&lt;[u8]&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;I: IntoIterator&lt;Item = (K, u64)&gt;,</span></h4></section></summary><div class="docblock"><p>Create a <code>Map</code> from an iterator of lexicographically ordered byte
strings and associated values.</p>
<p>If the iterator does not yield unique keys in lexicographic order, then
an error is returned.</p>
<p>Note that this is a convenience function to build a map in memory.
To build a map that streams to an arbitrary <code>io::Write</code>, use
<code>MapBuilder</code>.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Map%3CData%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#92-358">source</a><a href="#impl-Map%3CData%3E" class="anchor"></a><h3 class="code-header">impl&lt;Data:&nbsp;Deref&lt;Target = [u8]&gt;&gt; <a class="struct" href="map/struct.Map.html" title="struct tantivy_fst::map::Map">Map</a>&lt;Data&gt;</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.contains_key" class="method has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#105-107">source</a><h4 class="code-header">pub fn <a href="#method.contains_key" class="fnname">contains_key</a>&lt;K:&nbsp;AsRef&lt;[u8]&gt;&gt;(&amp;self, key: K) -&gt; bool</h4></section></summary><div class="docblock"><p>Tests the membership of a single key.</p>
<h5 id="example"><a href="#example">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tantivy_fst::Map;
<span class="kw">let </span>map = Map::from_iter(<span class="macro">vec!</span>[(<span class="string">&quot;a&quot;</span>, <span class="number">1</span>), (<span class="string">&quot;b&quot;</span>, <span class="number">2</span>), (<span class="string">&quot;c&quot;</span>, <span class="number">3</span>)]).unwrap();
<span class="macro">assert_eq!</span>(map.contains_key(<span class="string">&quot;b&quot;</span>), <span class="bool-val">true</span>);
<span class="macro">assert_eq!</span>(map.contains_key(<span class="string">&quot;z&quot;</span>), <span class="bool-val">false</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.get" class="method has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#123-125">source</a><h4 class="code-header">pub fn <a href="#method.get" class="fnname">get</a>&lt;K:&nbsp;AsRef&lt;[u8]&gt;&gt;(&amp;self, key: K) -&gt; Option&lt;u64&gt;</h4></section></summary><div class="docblock"><p>Retrieves the value associated with a key.</p>
<p>If the key does not exist, then <code>None</code> is returned.</p>
<h5 id="example-1"><a href="#example-1">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tantivy_fst::Map;
<span class="kw">let </span>map = Map::from_iter(<span class="macro">vec!</span>[(<span class="string">&quot;a&quot;</span>, <span class="number">1</span>), (<span class="string">&quot;b&quot;</span>, <span class="number">2</span>), (<span class="string">&quot;c&quot;</span>, <span class="number">3</span>)]).unwrap();
<span class="macro">assert_eq!</span>(map.get(<span class="string">&quot;b&quot;</span>), <span class="prelude-val">Some</span>(<span class="number">2</span>));
<span class="macro">assert_eq!</span>(map.get(<span class="string">&quot;z&quot;</span>), <span class="prelude-val">None</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.stream" class="method has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#160-162">source</a><h4 class="code-header">pub fn <a href="#method.stream" class="fnname">stream</a>(&amp;self) -&gt; <a class="struct" href="map/struct.Stream.html" title="struct tantivy_fst::map::Stream">Stream</a>&lt;'_&gt;</h4></section></summary><div class="docblock"><p>Return a lexicographically ordered stream of all key-value pairs in
this map.</p>
<p>While this is a stream, it does require heap space proportional to the
longest key in the map.</p>
<p>If the map is memory mapped, then no further heap space is needed.
Note though that your operating system may fill your page cache
(which will cause the resident memory usage of the process to go up
correspondingly).</p>
<h5 id="example-2"><a href="#example-2">Example</a></h5>
<p>Since streams are not iterators, the traditional <code>for</code> loop cannot be
used. <code>while let</code> is useful instead:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tantivy_fst::{IntoStreamer, Streamer, Map};
<span class="kw">let </span>map = Map::from_iter(<span class="macro">vec!</span>[(<span class="string">&quot;a&quot;</span>, <span class="number">1</span>), (<span class="string">&quot;b&quot;</span>, <span class="number">2</span>), (<span class="string">&quot;c&quot;</span>, <span class="number">3</span>)]).unwrap();
<span class="kw">let </span><span class="kw-2">mut </span>stream = map.stream();
<span class="kw">let </span><span class="kw-2">mut </span>kvs = <span class="macro">vec!</span>[];
<span class="kw">while let </span><span class="prelude-val">Some</span>((k, v)) = stream.next() {
kvs.push((k.to_vec(), v));
}
<span class="macro">assert_eq!</span>(kvs, <span class="macro">vec!</span>[
(<span class="string">b&quot;a&quot;</span>.to_vec(), <span class="number">1</span>),
(<span class="string">b&quot;b&quot;</span>.to_vec(), <span class="number">2</span>),
(<span class="string">b&quot;c&quot;</span>.to_vec(), <span class="number">3</span>),
]);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.keys" class="method has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#183-185">source</a><h4 class="code-header">pub fn <a href="#method.keys" class="fnname">keys</a>(&amp;self) -&gt; <a class="struct" href="map/struct.Keys.html" title="struct tantivy_fst::map::Keys">Keys</a>&lt;'_&gt;</h4></section></summary><div class="docblock"><p>Return a lexicographically ordered stream of all keys in this map.</p>
<p>Memory requirements are the same as described on <code>Map::stream</code>.</p>
<h5 id="example-3"><a href="#example-3">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tantivy_fst::{IntoStreamer, Streamer, Map};
<span class="kw">let </span>map = Map::from_iter(<span class="macro">vec!</span>[(<span class="string">&quot;a&quot;</span>, <span class="number">1</span>), (<span class="string">&quot;b&quot;</span>, <span class="number">2</span>), (<span class="string">&quot;c&quot;</span>, <span class="number">3</span>)]).unwrap();
<span class="kw">let </span><span class="kw-2">mut </span>stream = map.keys();
<span class="kw">let </span><span class="kw-2">mut </span>keys = <span class="macro">vec!</span>[];
<span class="kw">while let </span><span class="prelude-val">Some</span>(k) = stream.next() {
keys.push(k.to_vec());
}
<span class="macro">assert_eq!</span>(keys, <span class="macro">vec!</span>[<span class="string">b&quot;a&quot;</span>, <span class="string">b&quot;b&quot;</span>, <span class="string">b&quot;c&quot;</span>]);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.values" class="method has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#207-209">source</a><h4 class="code-header">pub fn <a href="#method.values" class="fnname">values</a>(&amp;self) -&gt; <a class="struct" href="map/struct.Values.html" title="struct tantivy_fst::map::Values">Values</a>&lt;'_&gt;</h4></section></summary><div class="docblock"><p>Return a stream of all values in this map ordered lexicographically
by each value’s corresponding key.</p>
<p>Memory requirements are the same as described on <code>Map::stream</code>.</p>
<h5 id="example-4"><a href="#example-4">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tantivy_fst::{IntoStreamer, Streamer, Map};
<span class="kw">let </span>map = Map::from_iter(<span class="macro">vec!</span>[(<span class="string">&quot;a&quot;</span>, <span class="number">1</span>), (<span class="string">&quot;b&quot;</span>, <span class="number">2</span>), (<span class="string">&quot;c&quot;</span>, <span class="number">3</span>)]).unwrap();
<span class="kw">let </span><span class="kw-2">mut </span>stream = map.values();
<span class="kw">let </span><span class="kw-2">mut </span>values = <span class="macro">vec!</span>[];
<span class="kw">while let </span><span class="prelude-val">Some</span>(v) = stream.next() {
values.push(v);
}
<span class="macro">assert_eq!</span>(values, <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.range" class="method has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#243-245">source</a><h4 class="code-header">pub fn <a href="#method.range" class="fnname">range</a>(&amp;self) -&gt; <a class="struct" href="map/struct.StreamBuilder.html" title="struct tantivy_fst::map::StreamBuilder">StreamBuilder</a>&lt;'_&gt;</h4></section></summary><div class="docblock"><p>Return a builder for range queries.</p>
<p>A range query returns a subset of key-value pairs in this map in a
range given in lexicographic order.</p>
<p>Memory requirements are the same as described on <code>Map::stream</code>.
Notably, only the keys in the range are read; keys outside the range
are not.</p>
<h5 id="example-5"><a href="#example-5">Example</a></h5>
<p>Returns only the key-value pairs in the range given.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tantivy_fst::{IntoStreamer, Streamer, Map};
<span class="kw">let </span>map = Map::from_iter(<span class="macro">vec!</span>[
(<span class="string">&quot;a&quot;</span>, <span class="number">1</span>), (<span class="string">&quot;b&quot;</span>, <span class="number">2</span>), (<span class="string">&quot;c&quot;</span>, <span class="number">3</span>), (<span class="string">&quot;d&quot;</span>, <span class="number">4</span>), (<span class="string">&quot;e&quot;</span>, <span class="number">5</span>),
]).unwrap();
<span class="kw">let </span><span class="kw-2">mut </span>stream = map.range().ge(<span class="string">&quot;b&quot;</span>).lt(<span class="string">&quot;e&quot;</span>).into_stream();
<span class="kw">let </span><span class="kw-2">mut </span>kvs = <span class="macro">vec!</span>[];
<span class="kw">while let </span><span class="prelude-val">Some</span>((k, v)) = stream.next() {
kvs.push((k.to_vec(), v));
}
<span class="macro">assert_eq!</span>(kvs, <span class="macro">vec!</span>[
(<span class="string">b&quot;b&quot;</span>.to_vec(), <span class="number">2</span>),
(<span class="string">b&quot;c&quot;</span>.to_vec(), <span class="number">3</span>),
(<span class="string">b&quot;d&quot;</span>.to_vec(), <span class="number">4</span>),
]);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.search" class="method has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#289-291">source</a><h4 class="code-header">pub fn <a href="#method.search" class="fnname">search</a>&lt;A:&nbsp;<a class="trait" href="automaton/trait.Automaton.html" title="trait tantivy_fst::automaton::Automaton">Automaton</a>&gt;(&amp;self, aut: A) -&gt; <a class="struct" href="map/struct.StreamBuilder.html" title="struct tantivy_fst::map::StreamBuilder">StreamBuilder</a>&lt;'_, A&gt;</h4></section></summary><div class="docblock"><p>Executes an automaton on the keys of this map.</p>
<p>Note that this returns a <code>StreamBuilder</code>, which can be used to
add a range query to the search (see the <code>range</code> method).</p>
<p>Memory requirements are the same as described on <code>Map::stream</code>.</p>
<h5 id="example-6"><a href="#example-6">Example</a></h5>
<p>An implementation of regular expressions for <code>Automaton</code> is available
in the <code>fst-regex</code> crate, which can be used to search maps.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code>
<span class="kw">use </span>std::error::Error;
<span class="kw">use </span>tantivy_fst::{IntoStreamer, Streamer, Map};
<span class="kw">use </span>tantivy_fst::Regex;
<span class="kw">fn </span>example() -&gt; <span class="prelude-ty">Result</span>&lt;(), Box&lt;Error&gt;&gt; {
<span class="kw">let </span>map = Map::from_iter(<span class="macro">vec!</span>[
(<span class="string">&quot;foo&quot;</span>, <span class="number">1</span>), (<span class="string">&quot;foo1&quot;</span>, <span class="number">2</span>), (<span class="string">&quot;foo2&quot;</span>, <span class="number">3</span>), (<span class="string">&quot;foo3&quot;</span>, <span class="number">4</span>), (<span class="string">&quot;foobar&quot;</span>, <span class="number">5</span>),
]).unwrap();
<span class="kw">let </span>re = Regex::new(<span class="string">&quot;f[a-z]+3?&quot;</span>).unwrap();
<span class="kw">let </span><span class="kw-2">mut </span>stream = map.search(<span class="kw-2">&amp;</span>re).into_stream();
<span class="kw">let </span><span class="kw-2">mut </span>kvs = <span class="macro">vec!</span>[];
<span class="kw">while let </span><span class="prelude-val">Some</span>((k, v)) = stream.next() {
kvs.push((k.to_vec(), v));
}
<span class="macro">assert_eq!</span>(kvs, <span class="macro">vec!</span>[
(<span class="string">b&quot;foo&quot;</span>.to_vec(), <span class="number">1</span>),
(<span class="string">b&quot;foo3&quot;</span>.to_vec(), <span class="number">4</span>),
(<span class="string">b&quot;foobar&quot;</span>.to_vec(), <span class="number">5</span>),
]);
<span class="prelude-val">Ok</span>(())
}
</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.len" class="method has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#295-297">source</a><h4 class="code-header">pub fn <a href="#method.len" class="fnname">len</a>(&amp;self) -&gt; usize</h4></section></summary><div class="docblock"><p>Returns the number of elements in this map.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.is_empty" class="method has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#301-303">source</a><h4 class="code-header">pub fn <a href="#method.is_empty" class="fnname">is_empty</a>(&amp;self) -&gt; bool</h4></section></summary><div class="docblock"><p>Returns true if and only if this map is empty.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.op" class="method has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#349-351">source</a><h4 class="code-header">pub fn <a href="#method.op" class="fnname">op</a>(&amp;self) -&gt; <a class="struct" href="map/struct.OpBuilder.html" title="struct tantivy_fst::map::OpBuilder">OpBuilder</a>&lt;'_&gt;</h4></section></summary><div class="docblock"><p>Creates a new map operation with this map added to it.</p>
<p>The <code>OpBuilder</code> type can be used to add additional map streams
and perform set operations like union, intersection, difference and
symmetric difference on the keys of the map. These set operations also
allow one to specify how conflicting values are merged in the stream.</p>
<h5 id="example-7"><a href="#example-7">Example</a></h5>
<p>This example demonstrates a union on multiple map streams. Notice that
the stream returned from the union is not a sequence of key-value
pairs, but rather a sequence of keys associated with one or more
values. Namely, a key is associated with each value associated with
that same key in the all of the streams.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tantivy_fst::{Streamer, Map};
<span class="kw">use </span>tantivy_fst::{map::IndexedValue};
<span class="kw">let </span>map1 = Map::from_iter(<span class="macro">vec!</span>[
(<span class="string">&quot;a&quot;</span>, <span class="number">1</span>), (<span class="string">&quot;b&quot;</span>, <span class="number">2</span>), (<span class="string">&quot;c&quot;</span>, <span class="number">3</span>),
]).unwrap();
<span class="kw">let </span>map2 = Map::from_iter(<span class="macro">vec!</span>[
(<span class="string">&quot;a&quot;</span>, <span class="number">10</span>), (<span class="string">&quot;y&quot;</span>, <span class="number">11</span>), (<span class="string">&quot;z&quot;</span>, <span class="number">12</span>),
]).unwrap();
<span class="kw">let </span><span class="kw-2">mut </span>union = map1.op().add(<span class="kw-2">&amp;</span>map2).union();
<span class="kw">let </span><span class="kw-2">mut </span>kvs = <span class="macro">vec!</span>[];
<span class="kw">while let </span><span class="prelude-val">Some</span>((k, vs)) = union.next() {
kvs.push((k.to_vec(), vs.to_vec()));
}
<span class="macro">assert_eq!</span>(kvs, <span class="macro">vec!</span>[
(<span class="string">b&quot;a&quot;</span>.to_vec(), <span class="macro">vec!</span>[
IndexedValue { index: <span class="number">0</span>, value: <span class="number">1 </span>},
IndexedValue { index: <span class="number">1</span>, value: <span class="number">10 </span>},
]),
(<span class="string">b&quot;b&quot;</span>.to_vec(), <span class="macro">vec!</span>[IndexedValue { index: <span class="number">0</span>, value: <span class="number">2 </span>}]),
(<span class="string">b&quot;c&quot;</span>.to_vec(), <span class="macro">vec!</span>[IndexedValue { index: <span class="number">0</span>, value: <span class="number">3 </span>}]),
(<span class="string">b&quot;y&quot;</span>.to_vec(), <span class="macro">vec!</span>[IndexedValue { index: <span class="number">1</span>, value: <span class="number">11 </span>}]),
(<span class="string">b&quot;z&quot;</span>.to_vec(), <span class="macro">vec!</span>[IndexedValue { index: <span class="number">1</span>, value: <span class="number">12 </span>}]),
]);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_fst" class="method has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#355-357">source</a><h4 class="code-header">pub fn <a href="#method.as_fst" class="fnname">as_fst</a>(&amp;self) -&gt; &amp;<a class="struct" href="raw/struct.Fst.html" title="struct tantivy_fst::raw::Fst">Fst</a>&lt;Data&gt;</h4></section></summary><div class="docblock"><p>Returns a reference to the underlying raw finite state transducer.</p>
</div></details></div></details></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-AsRef%3CFst%3CData%3E%3E-for-Map%3CData%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#385-390">source</a><a href="#impl-AsRef%3CFst%3CData%3E%3E-for-Map%3CData%3E" class="anchor"></a><h3 class="code-header">impl&lt;Data&gt; AsRef&lt;<a class="struct" href="raw/struct.Fst.html" title="struct tantivy_fst::raw::Fst">Fst</a>&lt;Data&gt;&gt; for <a class="struct" href="map/struct.Map.html" title="struct tantivy_fst::map::Map">Map</a>&lt;Data&gt;</h3></section></summary><div class="docblock"><p>Returns the underlying finite state transducer.</p>
</div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_ref" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#387-389">source</a><a href="#method.as_ref" class="anchor"></a><h4 class="code-header">fn <a class="fnname">as_ref</a>(&amp;self) -&gt; &amp;<a class="struct" href="raw/struct.Fst.html" title="struct tantivy_fst::raw::Fst">Fst</a>&lt;Data&gt;</h4></section></summary><div class='docblock'>Converts this type into a shared reference of the (usually inferred) input type.</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Debug-for-Map%3CData%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#360-374">source</a><a href="#impl-Debug-for-Map%3CData%3E" class="anchor"></a><h3 class="code-header">impl&lt;Data:&nbsp;Deref&lt;Target = [u8]&gt;&gt; Debug for <a class="struct" href="map/struct.Map.html" title="struct tantivy_fst::map::Map">Map</a>&lt;Data&gt;</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#361-373">source</a><a href="#method.fmt" class="anchor"></a><h4 class="code-header">fn <a class="fnname">fmt</a>(&amp;self, f: &amp;mut Formatter&lt;'_&gt;) -&gt; Result</h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-From%3CFst%3CData%3E%3E-for-Map%3CData%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#377-382">source</a><a href="#impl-From%3CFst%3CData%3E%3E-for-Map%3CData%3E" class="anchor"></a><h3 class="code-header">impl&lt;Data&gt; From&lt;<a class="struct" href="raw/struct.Fst.html" title="struct tantivy_fst::raw::Fst">Fst</a>&lt;Data&gt;&gt; for <a class="struct" href="map/struct.Map.html" title="struct tantivy_fst::map::Map">Map</a>&lt;Data&gt;</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#379-381">source</a><a href="#method.from" class="anchor"></a><h4 class="code-header">fn <a class="fnname">from</a>(fst: <a class="struct" href="raw/struct.Fst.html" title="struct tantivy_fst::raw::Fst">Fst</a>&lt;Data&gt;) -&gt; Self</h4></section></summary><div class='docblock'>Converts to this type from the input type.</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-IntoStreamer%3C%27a%3E-for-%26%27m%20Map%3CData%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#392-400">source</a><a href="#impl-IntoStreamer%3C%27a%3E-for-%26%27m%20Map%3CData%3E" class="anchor"></a><h3 class="code-header">impl&lt;'m, 'a, Data:&nbsp;Deref&lt;Target = [u8]&gt;&gt; <a class="trait" href="trait.IntoStreamer.html" title="trait tantivy_fst::IntoStreamer">IntoStreamer</a>&lt;'a&gt; for &amp;'m <a class="struct" href="map/struct.Map.html" title="struct tantivy_fst::map::Map">Map</a>&lt;Data&gt;</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Item" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Item" class="anchor"></a><h4 class="code-header">type <a href="trait.IntoStreamer.html#associatedtype.Item" class="associatedtype">Item</a> = (&amp;'a [u8], u64)</h4></section></summary><div class='docblock'>The type of the item emitted by the stream.</div></details><details class="rustdoc-toggle" open><summary><section id="associatedtype.Into" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Into" class="anchor"></a><h4 class="code-header">type <a href="trait.IntoStreamer.html#associatedtype.Into" class="associatedtype">Into</a> = <a class="struct" href="map/struct.Stream.html" title="struct tantivy_fst::map::Stream">Stream</a>&lt;'m, <a class="struct" href="automaton/struct.AlwaysMatch.html" title="struct tantivy_fst::automaton::AlwaysMatch">AlwaysMatch</a>&gt;</h4></section></summary><div class='docblock'>The type of the stream to be constructed.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into_stream" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/tantivy_fst/map.rs.html#397-399">source</a><a href="#method.into_stream" class="anchor"></a><h4 class="code-header">fn <a href="trait.IntoStreamer.html#tymethod.into_stream" class="fnname">into_stream</a>(self) -&gt; Self::<a class="associatedtype" href="trait.IntoStreamer.html#associatedtype.Into" title="type tantivy_fst::IntoStreamer::Into">Into</a></h4></section></summary><div class='docblock'>Construct a stream from <code>Self</code>.</div></details></div></details></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"><section id="impl-RefUnwindSafe-for-Map%3CData%3E" class="impl has-srclink"><a href="#impl-RefUnwindSafe-for-Map%3CData%3E" class="anchor"></a><h3 class="code-header">impl&lt;Data&gt; RefUnwindSafe for <a class="struct" href="map/struct.Map.html" title="struct tantivy_fst::map::Map">Map</a>&lt;Data&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Data: RefUnwindSafe,</span></h3></section><section id="impl-Send-for-Map%3CData%3E" class="impl has-srclink"><a href="#impl-Send-for-Map%3CData%3E" class="anchor"></a><h3 class="code-header">impl&lt;Data&gt; Send for <a class="struct" href="map/struct.Map.html" title="struct tantivy_fst::map::Map">Map</a>&lt;Data&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Data: Send,</span></h3></section><section id="impl-Sync-for-Map%3CData%3E" class="impl has-srclink"><a href="#impl-Sync-for-Map%3CData%3E" class="anchor"></a><h3 class="code-header">impl&lt;Data&gt; Sync for <a class="struct" href="map/struct.Map.html" title="struct tantivy_fst::map::Map">Map</a>&lt;Data&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Data: Sync,</span></h3></section><section id="impl-Unpin-for-Map%3CData%3E" class="impl has-srclink"><a href="#impl-Unpin-for-Map%3CData%3E" class="anchor"></a><h3 class="code-header">impl&lt;Data&gt; Unpin for <a class="struct" href="map/struct.Map.html" title="struct tantivy_fst::map::Map">Map</a>&lt;Data&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Data: Unpin,</span></h3></section><section id="impl-UnwindSafe-for-Map%3CData%3E" class="impl has-srclink"><a href="#impl-UnwindSafe-for-Map%3CData%3E" class="anchor"></a><h3 class="code-header">impl&lt;Data&gt; UnwindSafe for <a class="struct" href="map/struct.Map.html" title="struct tantivy_fst::map::Map">Map</a>&lt;Data&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Data: UnwindSafe,</span></h3></section></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Any-for-Map%3CData%3E" class="impl has-srclink"><a href="#impl-Any-for-Map%3CData%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; Any for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'static + ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl has-srclink"><a href="#method.type_id" class="anchor"></a><h4 class="code-header">fn <a class="fnname">type_id</a>(&amp;self) -&gt; TypeId</h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-Map%3CData%3E" class="impl has-srclink"><a href="#impl-Borrow%3CT%3E-for-Map%3CData%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; Borrow&lt;T&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span><a href="#method.borrow" class="anchor"></a><h4 class="code-header">fn <a class="fnname">borrow</a>(&amp;self) -&gt; &amp;T</h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-Map%3CData%3E" class="impl has-srclink"><a href="#impl-BorrowMut%3CT%3E-for-Map%3CData%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; BorrowMut&lt;T&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span><a href="#method.borrow_mut" class="anchor"></a><h4 class="code-header">fn <a class="fnname">borrow_mut</a>(&amp;mut self) -&gt; &amp;mut T</h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-Map%3CData%3E" class="impl has-srclink"><a href="#impl-From%3CT%3E-for-Map%3CData%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; From&lt;T&gt; for T</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from-1" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.from-1" class="anchor"></a><h4 class="code-header">fn <a class="fnname">from</a>(t: T) -&gt; T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-Map%3CData%3E" class="impl has-srclink"><a href="#impl-Into%3CU%3E-for-Map%3CData%3E" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; Into&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: From&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.into" class="anchor"></a><h4 class="code-header">fn <a class="fnname">into</a>(self) -&gt; U</h4></section></summary><div class="docblock"><p>Calls <code>U::from(self)</code>.</p>
<p>That is, this conversion is whatever the implementation of
<code>[From]&lt;T&gt; for U</code> chooses to do.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-Map%3CData%3E" class="impl has-srclink"><a href="#impl-TryFrom%3CU%3E-for-Map%3CData%3E" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; TryFrom&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: Into&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error-1" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Error</a> = Infallible</h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.try_from" class="anchor"></a><h4 class="code-header">fn <a class="fnname">try_from</a>(value: U) -&gt; Result&lt;T, &lt;T as TryFrom&lt;U&gt;&gt;::Error&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-Map%3CData%3E" class="impl has-srclink"><a href="#impl-TryInto%3CU%3E-for-Map%3CData%3E" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; TryInto&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: TryFrom&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Error</a> = &lt;U as TryFrom&lt;T&gt;&gt;::Error</h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.try_into" class="anchor"></a><h4 class="code-header">fn <a class="fnname">try_into</a>(self) -&gt; Result&lt;U, &lt;U as TryFrom&lt;T&gt;&gt;::Error&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details></div></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="tantivy_fst" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>