mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-24 18:36:24 +04:00
81 lines
20 KiB
HTML
81 lines
20 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="API documentation for the Rust `BitArray` trait in crate `bit_field`."><meta name="keywords" content="rust, rustlang, rust-lang, BitArray"><title>BitArray in bit_field - 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 trait"><!--[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">☰</button><a class="sidebar-logo" href="../bit_field/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div>
|
||
</a><h2 class="location"></h2>
|
||
</nav>
|
||
<nav class="sidebar"><a class="sidebar-logo" href="../bit_field/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div>
|
||
</a><h2 class="location"><a href="#">BitArray</a></h2><div class="sidebar-elems"><section><div class="block"><h3 class="sidebar-title"><a href="#required-methods">Required Methods</a></h3><ul><li><a href="#tymethod.bit_length">bit_length</a></li><li><a href="#tymethod.get_bit">get_bit</a></li><li><a href="#tymethod.get_bits">get_bits</a></li><li><a href="#tymethod.set_bit">set_bit</a></li><li><a href="#tymethod.set_bits">set_bits</a></li></ul></div><div class="block"><h3 class="sidebar-title"><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul><li><a href="#impl-BitArray%3CT%3E-for-%5BT%5D">[T]</a></li></ul></div><div class="block"><h3 class="sidebar-title"><a href="#implementors">Implementors</a></h3></div></section><h2 class="location"><a href="index.html">In bit_field</a></h2><div id="sidebar-vars" data-name="BitArray" data-ty="trait" 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="../bit_field/index.html"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></a><nav class="sub"><div class="theme-picker hidden"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"><img width="22" height="22" alt="Pick another theme!" src="../brush.svg"></button><div id="theme-choices" role="menu"></div></div><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"><button type="button" id="help-button" title="help">?</button><a id="settings-menu" href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></form></nav></div><section id="main-content" class="content"><div class="main-heading">
|
||
<h1 class="fqn"><span class="in-band">Trait <a href="index.html">bit_field</a>::<wbr><a class="trait" href="#">BitArray</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></h1><span class="out-of-band"><a class="srclink" href="../src/bit_field/lib.rs.html#111-206">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><div class="docblock item-decl"><pre class="rust trait"><code>pub trait BitArray<T: <a class="trait" href="trait.BitField.html" title="trait bit_field::BitField">BitField</a>> {
|
||
fn <a href="#tymethod.bit_length" class="fnname">bit_length</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.get_bit" class="fnname">get_bit</a>(&self, bit: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.get_bits" class="fnname">get_bits</a><U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/range/trait.RangeBounds.html" title="trait core::ops::range::RangeBounds">RangeBounds</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>>>(&self, range: U) -> T;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.set_bit" class="fnname">set_bit</a>(&mut self, bit: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>, value: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a>);
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.set_bits" class="fnname">set_bits</a><U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/range/trait.RangeBounds.html" title="trait core::ops::range::RangeBounds">RangeBounds</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>>>(&mut self, range: U, value: T);
|
||
}</code></pre></div><h2 id="required-methods" class="small-section-header">Required methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle" open><summary><div id="tymethod.bit_length" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/bit_field/lib.rs.html#120">source</a></div><h4 class="code-header">fn <a href="#tymethod.bit_length" class="fnname">bit_length</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a></h4></div></summary><div class="docblock"><p>Returns the length, eg number of bits, in this bit array.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">bit_field::BitArray</span>;
|
||
|
||
<span class="macro">assert_eq!</span>([<span class="number">0u8</span>, <span class="number">4u8</span>, <span class="number">8u8</span>].<span class="ident">bit_length</span>(), <span class="number">24</span>);
|
||
<span class="macro">assert_eq!</span>([<span class="number">0u32</span>, <span class="number">5u32</span>].<span class="ident">bit_length</span>(), <span class="number">64</span>);</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle" open><summary><div id="tymethod.get_bit" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/bit_field/lib.rs.html#137">source</a></div><h4 class="code-header">fn <a href="#tymethod.get_bit" class="fnname">get_bit</a>(&self, bit: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a></h4></div></summary><div class="docblock"><p>Obtains the bit at the index <code>bit</code>; note that index 0 is the least significant bit, while
|
||
index <code>length() - 1</code> is the most significant bit.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">bit_field::BitArray</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">value</span>: [<span class="ident">u32</span>; <span class="number">1</span>] <span class="op">=</span> [<span class="number">0b110101</span>];
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">value</span>.<span class="ident">get_bit</span>(<span class="number">1</span>), <span class="bool-val">false</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">value</span>.<span class="ident">get_bit</span>(<span class="number">2</span>), <span class="bool-val">true</span>);</code></pre></div>
|
||
<h6 id="panics"><a href="#panics">Panics</a></h6>
|
||
<p>This method will panic if the bit index is out of bounds of the bit array.</p>
|
||
</div></details><details class="rustdoc-toggle" open><summary><div id="tymethod.get_bits" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/bit_field/lib.rs.html#158">source</a></div><h4 class="code-header">fn <a href="#tymethod.get_bits" class="fnname">get_bits</a><U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/range/trait.RangeBounds.html" title="trait core::ops::range::RangeBounds">RangeBounds</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>>>(&self, range: U) -> T</h4></div></summary><div class="docblock"><p>Obtains the range of bits specified by <code>range</code>; note that index 0 is the least significant
|
||
bit, while index <code>length() - 1</code> is the most significant bit.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">bit_field::BitArray</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">value</span>: [<span class="ident">u32</span>; <span class="number">2</span>] <span class="op">=</span> [<span class="number">0b110101</span>, <span class="number">0b11</span>];
|
||
|
||
<span class="macro">assert_eq!</span>(<span class="ident">value</span>.<span class="ident">get_bits</span>(<span class="number">0</span>..<span class="number">3</span>), <span class="number">0b101</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">value</span>.<span class="ident">get_bits</span>(..<span class="number">6</span>), <span class="number">0b110101</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">value</span>.<span class="ident">get_bits</span>(<span class="number">31</span>..<span class="number">33</span>), <span class="number">0b10</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">value</span>.<span class="ident">get_bits</span>(<span class="number">5</span>..<span class="op">=</span><span class="number">32</span>), <span class="number">0b1_0000_0000_0000_0000_0000_0000_001</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">value</span>.<span class="ident">get_bits</span>(<span class="number">34</span>..), <span class="number">0</span>);</code></pre></div>
|
||
<h6 id="panics-1"><a href="#panics-1">Panics</a></h6>
|
||
<p>This method will panic if the start or end indexes of the range are out of bounds of the
|
||
bit array, or if the range can’t be contained by the bit field T.</p>
|
||
</div></details><details class="rustdoc-toggle" open><summary><div id="tymethod.set_bit" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/bit_field/lib.rs.html#182">source</a></div><h4 class="code-header">fn <a href="#tymethod.set_bit" class="fnname">set_bit</a>(&mut self, bit: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>, value: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a>)</h4></div></summary><div class="docblock"><p>Sets the bit at the index <code>bit</code> to the value <code>value</code> (where true means a value of ‘1’ and
|
||
false means a value of ‘0’); note that index 0 is the least significant bit, while index
|
||
<code>length() - 1</code> is the most significant bit.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">bit_field::BitArray</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">value</span> <span class="op">=</span> [<span class="number">0u32</span>];
|
||
|
||
<span class="ident">value</span>.<span class="ident">set_bit</span>(<span class="number">1</span>, <span class="bool-val">true</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">value</span>, [<span class="number">2u32</span>]);
|
||
|
||
<span class="ident">value</span>.<span class="ident">set_bit</span>(<span class="number">3</span>, <span class="bool-val">true</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">value</span>, [<span class="number">10u32</span>]);
|
||
|
||
<span class="ident">value</span>.<span class="ident">set_bit</span>(<span class="number">1</span>, <span class="bool-val">false</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">value</span>, [<span class="number">8u32</span>]);</code></pre></div>
|
||
<h6 id="panics-2"><a href="#panics-2">Panics</a></h6>
|
||
<p>This method will panic if the bit index is out of the bounds of the bit array.</p>
|
||
</div></details><details class="rustdoc-toggle" open><summary><div id="tymethod.set_bits" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/bit_field/lib.rs.html#205">source</a></div><h4 class="code-header">fn <a href="#tymethod.set_bits" class="fnname">set_bits</a><U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/range/trait.RangeBounds.html" title="trait core::ops::range::RangeBounds">RangeBounds</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>>>(&mut self, range: U, value: T)</h4></div></summary><div class="docblock"><p>Sets the range of bits defined by the range <code>range</code> to the lower bits of <code>value</code>; to be
|
||
specific, if the range is N bits long, the N lower bits of <code>value</code> will be used; if any of
|
||
the other bits in <code>value</code> are set to 1, this function will panic.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">bit_field::BitArray</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">value</span> <span class="op">=</span> [<span class="number">0u32</span>, <span class="number">0u32</span>];
|
||
|
||
<span class="ident">value</span>.<span class="ident">set_bits</span>(<span class="number">0</span>..<span class="number">2</span>, <span class="number">0b11</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">value</span>, [<span class="number">0b11</span>, <span class="number">0u32</span>]);
|
||
|
||
<span class="ident">value</span>.<span class="ident">set_bits</span>(<span class="number">31</span>..<span class="number">35</span>, <span class="number">0b1010</span>);
|
||
<span class="macro">assert_eq!</span>(<span class="ident">value</span>, [<span class="number">0x0003</span>, <span class="number">0b101</span>]);</code></pre></div>
|
||
<h6 id="panics-3"><a href="#panics-3">Panics</a></h6>
|
||
<p>This method will panic if the range is out of bounds of the bit array,
|
||
if the range can’t be contained by the bit field T, or if there are <code>1</code>s
|
||
not in the lower N bits of <code>value</code>.</p>
|
||
</div></details></div><h2 id="foreign-impls" class="small-section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor"></a></h2><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-BitArray%3CT%3E-for-%5BT%5D" class="impl has-srclink"><span class="rightside"><a class="srclink" href="../src/bit_field/lib.rs.html#275-351">source</a></span><a href="#impl-BitArray%3CT%3E-for-%5BT%5D" class="anchor"></a><h3 class="code-header in-band">impl<T: <a class="trait" href="trait.BitField.html" title="trait bit_field::BitField">BitField</a>> <a class="trait" href="trait.BitArray.html" title="trait bit_field::BitArray">BitArray</a><T> for <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">[</a>T<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">]</a></h3></section></summary><div class="impl-items"><section id="method.bit_length" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="../src/bit_field/lib.rs.html#277-279">source</a></span><a href="#method.bit_length" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.bit_length" class="fnname">bit_length</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a></h4></section><section id="method.get_bit" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="../src/bit_field/lib.rs.html#282-286">source</a></span><a href="#method.get_bit" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.get_bit" class="fnname">get_bit</a>(&self, bit: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a></h4></section><section id="method.get_bits" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="../src/bit_field/lib.rs.html#289-314">source</a></span><a href="#method.get_bits" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.get_bits" class="fnname">get_bits</a><U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/range/trait.RangeBounds.html" title="trait core::ops::range::RangeBounds">RangeBounds</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>>>(&self, range: U) -> T</h4></section><section id="method.set_bit" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="../src/bit_field/lib.rs.html#317-321">source</a></span><a href="#method.set_bit" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.set_bit" class="fnname">set_bit</a>(&mut self, bit: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>, value: <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.bool.html">bool</a>)</h4></section><section id="method.set_bits" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="../src/bit_field/lib.rs.html#324-350">source</a></span><a href="#method.set_bits" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.set_bits" class="fnname">set_bits</a><U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/range/trait.RangeBounds.html" title="trait core::ops::range::RangeBounds">RangeBounds</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.usize.html">usize</a>>>(&mut self, range: U, value: T)</h4></section></div></details><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"></div><script type="text/javascript" src="../implementors/bit_field/trait.BitArray.js" async></script></section><section id="search" class="content hidden"></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="bit_field" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.62.0-nightly (1f7fb6413 2022-04-10)" ></div>
|
||
</body></html> |