Files
greptimedb/common_base/bit_vec/prelude/macro.bitarr.html
2025-12-23 10:07:07 +00:00

68 lines
8.5 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="Bit-Array Value Constructor"><title>bitarr in common_base::bit_vec::prelude - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../static.files/rustdoc-e56847b5.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="common_base" data-themes="" data-resource-suffix="" data-rustdoc-version="1.92.0-nightly (fa3155a64 2025-09-30)" data-channel="nightly" data-search-js="search-e256b49e.js" data-stringdex-js="stringdex-828709d0.js" data-settings-js="settings-c38705f0.js" ><script src="../../../static.files/storage-e2aeef58.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-ce535bd0.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-044be391.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]--><rustdoc-topbar><h2><a href="#">bitarr</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../common_base/index.html">common_<wbr>base</a><span class="version">1.0.0-beta.3</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">bitarr</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#bit-array-value-constructor" title="Bit-Array Value Constructor">Bit-Array Value Constructor</a><ul><li><a href="#argument-syntax" title="Argument Syntax">Argument Syntax</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In common_<wbr>base::<wbr>bit_<wbr>vec::<wbr>prelude</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../index.html">common_base</a>::<wbr><a href="../index.html">bit_vec</a>::<wbr><a href="index.html">prelude</a></div><h1>Macro <span class="macro">bitarr</span>&nbsp;<button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"></span></div><pre class="rust item-decl"><code>macro_rules! bitarr {
(const Cell&lt;$store:ident&gt;, $order:ident; $($val:expr),* $(,)?) =&gt; { ... };
(const $store:ident, $order:ident; $($val:expr),* $(,)?) =&gt; { ... };
(const $store:ty, $order:ty; $val:expr; $len:expr) =&gt; { ... };
(const $val:expr; $len:expr) =&gt; { ... };
(const $($val:expr),* $(,)?) =&gt; { ... };
(Cell&lt;$store:ident&gt;, $order:ident; $($val:expr),* $(,)?) =&gt; { ... };
(Cell&lt;$store:ident&gt;, $order:path; $($val:expr),* $(,)?) =&gt; { ... };
($store:ident, $order:ident; $($val:expr),* $(,)?) =&gt; { ... };
($store:ident, $order:path; $($val:expr),* $(,)?) =&gt; { ... };
($store:ty, $order:ty; $val:expr; $len:expr) =&gt; { ... };
($val:expr; $len:expr) =&gt; { ... };
($($val:expr),* $(,)?) =&gt; { ... };
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><h2 id="bit-array-value-constructor"><a class="doc-anchor" href="#bit-array-value-constructor">§</a>Bit-Array Value Constructor</h2>
<p>This macro provides a bit-initializer syntax for <a href="struct.BitArray.html" title="struct common_base::bit_vec::prelude::BitArray"><code>BitArray</code></a> values. It takes a
superset of the <a href="https://doc.rust-lang.org/nightly/alloc/macro.vec.html" title="macro alloc::vec"><code>vec!</code></a> arguments, and is capable of producing bit-arrays in
<code>const</code> contexts (for known type parameters).</p>
<p>Like <code>vec!</code>, it can accept a sequence of comma-separated bit values, or a
semicolon-separated pair of a bit value and a repetition counter. Bit values may
be any integer or name of a <code>const</code> integer, but <em>should</em> only be <code>0</code> or <code>1</code>.</p>
<h3 id="argument-syntax"><a class="doc-anchor" href="#argument-syntax">§</a>Argument Syntax</h3>
<p>It accepts zero, one, or three prefix arguments:</p>
<ul>
<li>
<p><code>const</code>: If the first argument to the macro is the keyword <code>const</code>, separated
from remaining arguments by a space, then the macro expands to a
<code>const</code>-expression that can be used in any appropriate context (initializing
a <code>static</code>, a <code>const</code>, or passed to a <code>const fn</code>). This only works when the
bit-ordering argument is either implicit, or one of the three tokens that
<code>bitvec</code> can recognize.</p>
</li>
<li>
<p><code>$order ,</code>: When this is one of the three literal tokens <code>LocalBits</code>, <code>Lsb0</code>,
or <code>Msb0</code>, then the macro is able to compute the encoded bit-array contents at
compile time, including in <code>const</code> contexts. When it is anything else, the
encoding must take place at runtime. The name or path chosen must be in scope
at the macro invocation site.</p>
<p>When not provided, this defaults to <code>Lbs0</code>.</p>
</li>
<li>
<p><code>$store ;</code>: This must be one of <code>uTYPE</code>, <code>Cell&lt;uTYPE&gt;</code>, <code>AtomicUTYPE</code>, or
<code>RadiumUTYPE</code> where <code>TYPE</code> is one of <code>8</code>, <code>16</code>, <code>32</code>, <code>64</code>, or <code>size</code>. The
macro recognizes this token textually, and does not have access to the type
system resolver, so it will not accept aliases or qualified paths.</p>
<p>When not provided, this defaults to <code>usize</code>.</p>
</li>
</ul>
<p>The <code>const</code> argument can be present or absent independently of the
type-parameter pair. The pair must be either both absent or both present
together.</p>
<blockquote>
<p>Previous versions of <code>bitvec</code> supported <code>$order</code>-only arguments. This has been
removed for clarity of use and ease of implementation.</p>
</blockquote>
<h3 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h3>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>bitvec::prelude::<span class="kw-2">*</span>;
<span class="kw">use </span>core::{cell::Cell, mem};
<span class="kw">use </span>radium::types::<span class="kw-2">*</span>;
<span class="kw">let </span>a: BitArray = <span class="macro">bitarr!</span>[<span class="number">0</span>, <span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>];
<span class="kw">let </span>b: BitArray = <span class="macro">bitarr!</span>[<span class="number">1</span>; <span class="number">5</span>];
<span class="macro">assert_eq!</span>(b.len(), mem::size_of::&lt;usize&gt;() * <span class="number">8</span>);
<span class="kw">let </span>c = <span class="macro">bitarr!</span>[u16, Lsb0; <span class="number">0</span>, <span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>];
<span class="kw">let </span>d = <span class="macro">bitarr!</span>[Cell&lt;u16&gt;, Msb0; <span class="number">1</span>; <span class="number">10</span>];
<span class="kw">const </span>E: BitArray&lt;[u32; <span class="number">1</span>], LocalBits&gt; = <span class="macro">bitarr!</span>[u32, LocalBits; <span class="number">1</span>; <span class="number">15</span>];
<span class="kw">let </span>f = <span class="macro">bitarr!</span>[RadiumU32, Msb0; <span class="number">1</span>; <span class="number">20</span>];</code></pre></div></div></details></section></div></main></body></html>