This repository has been archived on 2022-04-04. You can view files and clone it, but cannot push or open issues or pull requests.

55 lines
11 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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="This macro is like `include_bytes!` or `include_str!`, but compresses at compile time and lazily decompresses at runtime."><meta name="keywords" content="rust, rustlang, rust-lang, flate"><title>flate in include_flate - 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" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../ayu.css" disabled><link rel="stylesheet" type="text/css" href="../dark.css" disabled><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script 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 macro"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">&#9776;</div><a class="sidebar-logo" href="../include_flate/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.png" alt="logo"></div>
</a><div class="sidebar-elems"><h2 class="location">Other items in<br><a href="index.html">include_flate</a></h2><div id="sidebar-vars" data-name="flate" data-ty="macro" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../include_flate/index.html"><img class="rust-logo" src="../rust-logo.png" alt="logo"></a><nav class="sub"><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"><img width="18" height="18" alt="Pick another theme!" src="../brush.svg"></button><div id="theme-choices" role="menu"></div></div><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" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><button type="button" id="help-button" title="help">?</button><a id="settings-menu" href="../settings.html" title="settings"><img width="18" height="18" alt="Change settings" src="../wheel.svg"></a></div></form></nav></div><section id="main-content" class="content"><h1 class="fqn"><span class="in-band">Macro <a href="index.html">include_flate</a>::<wbr><a class="macro" href="#">flate</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></span><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">&#x2212;</span>]</a></span><a class="srclink" href="../src/include_flate/lib.rs.html#94-109" title="goto source code">[src]</a></span></h1><div class="docblock item-decl"><div class="example-wrap"><pre class="rust macro"><code><span class="macro">macro_rules!</span> <span class="ident">flate</span> {
($(<span class="attribute">#[<span class="macro-nonterminal">$</span><span class="macro-nonterminal">meta</span> : <span class="ident">meta</span>]</span>) <span class="op">*</span> $(<span class="kw">pub</span> $(($(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">vis</span> : <span class="ident">tt</span>) <span class="op">+</span>)) <span class="question-mark">?</span>) <span class="question-mark">?</span> <span class="kw">static</span> <span class="macro-nonterminal">$</span><span class="macro-nonterminal">name</span> : <span class="ident">ident</span> :
[<span class="ident">u8</span>] <span class="ident">from</span> <span class="macro-nonterminal">$</span><span class="macro-nonterminal">path</span> : <span class="ident">literal</span>) =&gt; { ... };
($(<span class="attribute">#[<span class="macro-nonterminal">$</span><span class="macro-nonterminal">meta</span> : <span class="ident">meta</span>]</span>) <span class="op">*</span> $(<span class="kw">pub</span> $(($(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">vis</span> : <span class="ident">tt</span>) <span class="op">+</span>)) <span class="question-mark">?</span>) <span class="question-mark">?</span> <span class="kw">static</span> <span class="macro-nonterminal">$</span><span class="macro-nonterminal">name</span> : <span class="ident">ident</span> :
<span class="ident">str</span> <span class="ident">from</span> <span class="macro-nonterminal">$</span><span class="macro-nonterminal">path</span> : <span class="ident">literal</span>) =&gt; { ... };
}</code></pre></div>
</div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>This macro is like <a href="https://doc.rust-lang.org/std/macro.include_bytes.html"><code>include_bytes!</code></a> or <a href="https://doc.rust-lang.org/std/macro.include_str.html"><code>include_str!</code></a>, but compresses at compile time
and lazily decompresses at runtime.</p>
<h2 id="parameters" class="section-header"><a href="#parameters">Parameters</a></h2>
<p>The macro can be used like this:</p>
<div class='information'><div class='tooltip ignore'></div></div><div class="example-wrap"><pre class="rust rust-example-rendered ignore"><code><span class="macro">flate!</span>(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">meta</span> <span class="macro-nonterminal">$</span><span class="macro-nonterminal">vis</span> <span class="kw">static</span> <span class="macro-nonterminal">$</span><span class="macro-nonterminal">name</span>: <span class="macro-nonterminal">$</span><span class="kw">type</span> <span class="macro-nonterminal">from</span> <span class="macro-nonterminal">$</span><span class="macro-nonterminal">file</span>);</code></pre></div>
<ul>
<li><code>$meta</code> is zero or more <code>#[...]</code> attributes that can be applied on the static parameters of
<code>lazy_static</code>. For the actual semantics of the meta attributes, please refer to
<a href="https://docs.rs/lazy_static/1.3.0/lazy_static/"><code>lazy_static</code></a> documentation.</li>
<li><code>$vis</code> is a visibility modifier (e.g. <code>pub</code>, <code>pub(crate)</code>) or empty.</li>
<li><code>$name</code> is the name of the static variable..</li>
<li><code>$type</code> can be either <code>[u8]</code> or <code>str</code>. However, the actual type created would dereference
into <code>Vec&lt;u8&gt;</code> and <code>String</code> (although they are <code>AsRef&lt;[u8]&gt;</code> and <code>AsRef&lt;str&gt;</code>) respectively.</li>
<li><code>$file</code> is either an absolute path or a path relative to the current
<a href="https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates"><code>CARGO_MANIFEST_DIR</code></a>. Note that <strong>this is distinct from the behaviour of the builtin
<code>include_bytes!</code>/<code>include_str!</code> macros</strong><code>includle_bytes!</code>/<code>include_str!</code> paths are
relative to the current source file, while <code>flate!</code> paths are relative to <code>CARGO_MANIFEST_DIR</code>.</li>
</ul>
<h2 id="returns" class="section-header"><a href="#returns">Returns</a></h2>
<p>The macro expands to a <a href="https://docs.rs/lazy_static/1.3.0/lazy_static/"><code>lazy_static</code></a> call, which lazily inflates the compressed bytes.</p>
<h2 id="compile-errors" class="section-header"><a href="#compile-errors">Compile errors</a></h2>
<ul>
<li>If the input format is incorrect</li>
<li>If the referenced file does not exist or is not readable</li>
<li>If <code>$type</code> is <code>str</code> but the file is not fully valid UTF-8</li>
</ul>
<h2 id="algorithm" class="section-header"><a href="#algorithm">Algorithm</a></h2>
<p>Compression and decompression use the DEFLATE algorithm from <a href="https://docs.rs/libflate/0.1.26/libflate/"><code>libflate</code></a>.</p>
<h2 id="examples" class="section-header"><a href="#examples">Examples</a></h2>
<p>Below are some basic examples. For actual compiled examples, see the <a href="https://github.com/SOF3/include-flate/tree/master/tests"><code>tests</code></a> directory.</p>
<div class='information'><div class='tooltip ignore'></div></div><div class="example-wrap"><pre class="rust rust-example-rendered ignore"><code><span class="comment">// This declares a `static VAR_NAME: impl Deref&lt;Vec&lt;u8&gt;&gt;`</span>
<span class="macro">flate!</span>(<span class="kw">static</span> <span class="ident">VAR_NAME</span>: [<span class="ident">u8</span>] <span class="ident">from</span> <span class="string">&quot;binary-file.dat&quot;</span>);
<span class="comment">// This declares a `static VAR_NAME: impl Deref&lt;String&gt;`</span>
<span class="macro">flate!</span>(<span class="kw">static</span> <span class="ident">VAR_NAME</span>: <span class="ident">str</span> <span class="ident">from</span> <span class="string">&quot;text-file.txt&quot;</span>);
<span class="comment">// Visibility modifiers can be added in the front</span>
<span class="macro">flate!</span>(<span class="kw">pub</span> <span class="kw">static</span> <span class="ident">VAR_NAME</span>: <span class="ident">str</span> <span class="ident">from</span> <span class="string">&quot;public-file.txt&quot;</span>);
<span class="comment">// Meta attributes can also be added</span>
<span class="macro">flate!</span>(<span class="attribute">#[<span class="ident">allow</span>(<span class="ident">unused</span>)]</span>
<span class="attribute">#[<span class="ident">doc</span> <span class="op">=</span> <span class="string">&quot;Example const&quot;</span>]</span>
<span class="kw">pub</span> <span class="kw">static</span> <span class="ident">VAR_NAME</span>: <span class="ident">str</span> <span class="ident">from</span> <span class="string">&quot;file.txt&quot;</span>);</code></pre></div>
</div></details></section><section id="search" class="content hidden"></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="include_flate" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.59.0 (9d1b2106e 2022-02-23)" ></div>
</body></html>