diff options
author | 2015-06-29 20:16:15 +0000 | |
---|---|---|
committer | 2015-06-29 20:16:15 +0000 | |
commit | 64106c4d3d4ddba8c7bc2af75376e6d3d3d75601 (patch) | |
tree | 8c64d6e8be006486d975a651505fbbde61365cd6 /bitflags | |
download | irsc-gh-pages.tar.gz irsc-gh-pages.tar.xz irsc-gh-pages.zip |
Update documentationgh-pages
Diffstat (limited to 'bitflags')
-rw-r--r-- | bitflags/index.html | 113 | ||||
-rw-r--r-- | bitflags/macro.bitflags!.html | 380 | ||||
-rw-r--r-- | bitflags/sidebar-items.js | 1 |
3 files changed, 494 insertions, 0 deletions
diff --git a/bitflags/index.html b/bitflags/index.html new file mode 100644 index 0000000..041b5ef --- /dev/null +++ b/bitflags/index.html @@ -0,0 +1,113 @@ +<!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 `bitflags` crate."> + <meta name="keywords" content="rust, rustlang, rust-lang, bitflags"> + + <title>bitflags - Rust</title> + + <link rel="stylesheet" type="text/css" href="../main.css"> + + + +</head> +<body class="rustdoc"> + <!--[if lte IE 8]> + <div class="warning"> + This old browser is unsupported and will most likely display funky + things. + </div> + <![endif]--> + + + + <section class="sidebar"> + + <p class='location'></p><script>window.sidebarCurrent = {name: 'bitflags', ty: 'mod', relpath: '../'};</script> + </section> + + <nav class="sub"> + <form class="search-form js-only"> + <div class="search-container"> + <input class="search-input" name="search" + autocomplete="off" + placeholder="Click or press 'S' to search, '?' for more options..." + type="search"> + </div> + </form> + </nav> + + <section id='main' class="content mod"> +<h1 class='fqn'><span class='in-band'>Crate <a class='mod' href=''>bitflags</a></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'>−</span>] + </a> + </span><a id='src-0' class='srclink' href='../src/bitflags/lib.rs.html#11-512' title='goto source code'>[src]</a></span></h1> +<div class='docblock'><p>A typesafe bitmask flag generator.</p> +</div><h2 id='macros' class='section-header'><a href="#macros">Macros</a></h2> +<table> + <tr class=' module-item'> + <td><a class='macro' href='macro.bitflags!.html' + title='bitflags::bitflags!'>bitflags!</a></td> + <td class='docblock short'> + <p>The <code>bitflags!</code> macro generates a <code>struct</code> that holds a set of C-style +bitmask flags. It is useful for creating typesafe wrappers for C APIs.</p> + + </td> + </tr> + </table></section> + <section id='search' class="content hidden"></section> + + <section class="footer"></section> + + <div id="help" class="hidden"> + <div class="shortcuts"> + <h1>Keyboard shortcuts</h1> + <dl> + <dt>?</dt> + <dd>Show this help dialog</dd> + <dt>S</dt> + <dd>Focus the search field</dd> + <dt>⇤</dt> + <dd>Move up in search results</dd> + <dt>⇥</dt> + <dd>Move down in search results</dd> + <dt>⏎</dt> + <dd>Go to active search result</dd> + </dl> + </div> + <div class="infos"> + <h1>Search tricks</h1> + <p> + Prefix searches with a type followed by a colon (e.g. + <code>fn:</code>) to restrict the search to a given type. + </p> + <p> + Accepted types are: <code>fn</code>, <code>mod</code>, + <code>struct</code>, <code>enum</code>, + <code>trait</code>, <code>typedef</code> (or + <code>tdef</code>). + </p> + <p> + Search functions by type signature (e.g. + <code>vec -> usize</code>) + </p> + </div> + </div> + + + + <script> + window.rootPath = "../"; + window.currentCrate = "bitflags"; + window.playgroundUrl = ""; + </script> + <script src="../jquery.js"></script> + <script src="../main.js"></script> + + <script async src="../search-index.js"></script> +</body> +</html>
\ No newline at end of file diff --git a/bitflags/macro.bitflags!.html b/bitflags/macro.bitflags!.html new file mode 100644 index 0000000..920f42c --- /dev/null +++ b/bitflags/macro.bitflags!.html @@ -0,0 +1,380 @@ +<!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 `bitflags!` macro in crate `bitflags`."> + <meta name="keywords" content="rust, rustlang, rust-lang, bitflags!"> + + <title>bitflags::bitflags! - Rust</title> + + <link rel="stylesheet" type="text/css" href="../main.css"> + + + +</head> +<body class="rustdoc"> + <!--[if lte IE 8]> + <div class="warning"> + This old browser is unsupported and will most likely display funky + things. + </div> + <![endif]--> + + + + <section class="sidebar"> + + <p class='location'><a href='index.html'>bitflags</a></p><script>window.sidebarCurrent = {name: 'bitflags!', ty: 'macro', relpath: ''};</script><script defer src="sidebar-items.js"></script> + </section> + + <nav class="sub"> + <form class="search-form js-only"> + <div class="search-container"> + <input class="search-input" name="search" + autocomplete="off" + placeholder="Click or press 'S' to search, '?' for more options..." + type="search"> + </div> + </form> + </nav> + + <section id='main' class="content macro"> +<h1 class='fqn'><span class='in-band'><a href='index.html'>bitflags</a>::<wbr><a class='macro' href=''>bitflags!</a></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'>−</span>] + </a> + </span><a id='src-4' class='srclink' href='../src/bitflags/lib.rs.html#127-288' title='goto source code'>[src]</a></span></h1> +<pre class='rust macro'> +<span class='macro'>macro_rules</span><span class='macro'>!</span> <span class='ident'>bitflags</span> { + ($(<span class='attribute'>#[<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>attr</span>:<span class='ident'>meta</span>]</span>)<span class='op'>*</span> <span class='ident'>flags</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>:<span class='ident'>ident</span>: <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>T</span>:<span class='ident'>ty</span> { + $($(<span class='attribute'>#[<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>Flag_attr</span>:<span class='ident'>meta</span>]</span>)<span class='op'>*</span> <span class='kw'>const</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>Flag</span>:<span class='ident'>ident</span> <span class='op'>=</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>value</span>:<span class='ident'>expr</span>),<span class='op'>+</span> + }) <span class='op'>=></span> { + <span class='attribute'>#[<span class='ident'>derive</span>(<span class='ident'>Copy</span>, <span class='ident'>PartialEq</span>, <span class='ident'>Eq</span>, <span class='ident'>Clone</span>, <span class='ident'>PartialOrd</span>, <span class='ident'>Ord</span>, <span class='ident'>Hash</span>)]</span> + $(<span class='attribute'>#[<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>attr</span>]</span>)<span class='op'>*</span> + <span class='kw'>pub</span> <span class='kw'>struct</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { + <span class='ident'>bits</span>: <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>T</span>, + } + + $($(<span class='attribute'>#[<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>Flag_attr</span>]</span>)<span class='op'>*</span> <span class='kw'>pub</span> <span class='kw'>const</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>Flag</span>: <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> <span class='op'>=</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { <span class='ident'>bits</span>: <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>value</span> };)<span class='op'>+</span> + + <span class='kw'>impl</span> ::<span class='ident'>std</span>::<span class='ident'>fmt</span>::<span class='ident'>Debug</span> <span class='kw'>for</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { + <span class='kw'>fn</span> <span class='ident'>fmt</span>(<span class='kw-2'>&</span><span class='self'>self</span>, <span class='ident'>f</span>: <span class='kw-2'>&</span><span class='kw-2'>mut</span> ::<span class='ident'>std</span>::<span class='ident'>fmt</span>::<span class='ident'>Formatter</span>) <span class='op'>-></span> ::<span class='ident'>std</span>::<span class='ident'>fmt</span>::<span class='prelude-ty'>Result</span> { + <span class='kw'>let</span> <span class='ident'>out</span> <span class='op'>=</span> <span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{} {{ bits: {:#b} }}"</span>, + <span class='macro'>stringify</span><span class='macro'>!</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>), + <span class='self'>self</span>.<span class='ident'>bits</span>); + <span class='ident'>f</span>.<span class='ident'>write_str</span>(<span class='kw-2'>&</span><span class='ident'>out</span>[..]) + } + } + + <span class='kw'>impl</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { + <span class='doccomment'>/// Returns an empty set of flags.</span> + <span class='attribute'>#[<span class='ident'>inline</span>]</span> + <span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>empty</span>() <span class='op'>-></span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { + <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { <span class='ident'>bits</span>: <span class='number'>0</span> } + } + + <span class='doccomment'>/// Returns the set containing all flags.</span> + <span class='attribute'>#[<span class='ident'>inline</span>]</span> + <span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>all</span>() <span class='op'>-></span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { + <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { <span class='ident'>bits</span>: $(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>value</span>)<span class='op'>|</span><span class='op'>+</span> } + } + + <span class='doccomment'>/// Returns the raw value of the flags currently stored.</span> + <span class='attribute'>#[<span class='ident'>inline</span>]</span> + <span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>bits</span>(<span class='kw-2'>&</span><span class='self'>self</span>) <span class='op'>-></span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>T</span> { + <span class='self'>self</span>.<span class='ident'>bits</span> + } + + <span class='doccomment'>/// Convert from underlying bit representation, unless that</span> + <span class='doccomment'>/// representation contains bits that do not correspond to a flag.</span> + <span class='attribute'>#[<span class='ident'>inline</span>]</span> + <span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>from_bits</span>(<span class='ident'>bits</span>: <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>T</span>) <span class='op'>-></span> ::<span class='ident'>std</span>::<span class='ident'>option</span>::<span class='prelude-ty'>Option</span><span class='op'><</span><span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span><span class='op'>></span> { + <span class='kw'>if</span> (<span class='ident'>bits</span> <span class='kw-2'>&</span> <span class='op'>!</span><span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>::<span class='ident'>all</span>().<span class='ident'>bits</span>()) <span class='op'>!=</span> <span class='number'>0</span> { + ::<span class='ident'>std</span>::<span class='ident'>option</span>::<span class='prelude-ty'>Option</span>::<span class='prelude-val'>None</span> + } <span class='kw'>else</span> { + ::<span class='ident'>std</span>::<span class='ident'>option</span>::<span class='prelude-ty'>Option</span>::<span class='prelude-val'>Some</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { <span class='ident'>bits</span>: <span class='ident'>bits</span> }) + } + } + + <span class='doccomment'>/// Convert from underlying bit representation, dropping any bits</span> + <span class='doccomment'>/// that do not correspond to flags.</span> + <span class='attribute'>#[<span class='ident'>inline</span>]</span> + <span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>from_bits_truncate</span>(<span class='ident'>bits</span>: <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>T</span>) <span class='op'>-></span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { + <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { <span class='ident'>bits</span>: <span class='ident'>bits</span> } <span class='kw-2'>&</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>::<span class='ident'>all</span>() + } + + <span class='doccomment'>/// Returns `true` if no flags are currently stored.</span> + <span class='attribute'>#[<span class='ident'>inline</span>]</span> + <span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>is_empty</span>(<span class='kw-2'>&</span><span class='self'>self</span>) <span class='op'>-></span> <span class='ident'>bool</span> { + <span class='op'>*</span><span class='self'>self</span> <span class='op'>==</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>::<span class='ident'>empty</span>() + } + + <span class='doccomment'>/// Returns `true` if all flags are currently set.</span> + <span class='attribute'>#[<span class='ident'>inline</span>]</span> + <span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>is_all</span>(<span class='kw-2'>&</span><span class='self'>self</span>) <span class='op'>-></span> <span class='ident'>bool</span> { + <span class='op'>*</span><span class='self'>self</span> <span class='op'>==</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>::<span class='ident'>all</span>() + } + + <span class='doccomment'>/// Returns `true` if there are flags common to both `self` and `other`.</span> + <span class='attribute'>#[<span class='ident'>inline</span>]</span> + <span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>intersects</span>(<span class='kw-2'>&</span><span class='self'>self</span>, <span class='ident'>other</span>: <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>) <span class='op'>-></span> <span class='ident'>bool</span> { + <span class='op'>!</span>(<span class='op'>*</span><span class='self'>self</span> <span class='kw-2'>&</span> <span class='ident'>other</span>).<span class='ident'>is_empty</span>() + } + + <span class='doccomment'>/// Returns `true` all of the flags in `other` are contained within `self`.</span> + <span class='attribute'>#[<span class='ident'>inline</span>]</span> + <span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>contains</span>(<span class='kw-2'>&</span><span class='self'>self</span>, <span class='ident'>other</span>: <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>) <span class='op'>-></span> <span class='ident'>bool</span> { + (<span class='op'>*</span><span class='self'>self</span> <span class='kw-2'>&</span> <span class='ident'>other</span>) <span class='op'>==</span> <span class='ident'>other</span> + } + + <span class='doccomment'>/// Inserts the specified flags in-place.</span> + <span class='attribute'>#[<span class='ident'>inline</span>]</span> + <span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>insert</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>other</span>: <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>) { + <span class='self'>self</span>.<span class='ident'>bits</span> <span class='op'>|=</span> <span class='ident'>other</span>.<span class='ident'>bits</span>; + } + + <span class='doccomment'>/// Removes the specified flags in-place.</span> + <span class='attribute'>#[<span class='ident'>inline</span>]</span> + <span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>remove</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>other</span>: <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>) { + <span class='self'>self</span>.<span class='ident'>bits</span> <span class='op'>&=</span> <span class='op'>!</span><span class='ident'>other</span>.<span class='ident'>bits</span>; + } + + <span class='doccomment'>/// Toggles the specified flags in-place.</span> + <span class='attribute'>#[<span class='ident'>inline</span>]</span> + <span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>toggle</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>other</span>: <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>) { + <span class='self'>self</span>.<span class='ident'>bits</span> <span class='op'>^=</span> <span class='ident'>other</span>.<span class='ident'>bits</span>; + } + } + + <span class='kw'>impl</span> ::<span class='ident'>std</span>::<span class='ident'>ops</span>::<span class='ident'>BitOr</span> <span class='kw'>for</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { + <span class='kw'>type</span> <span class='ident'>Output</span> <span class='op'>=</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>; + + <span class='doccomment'>/// Returns the union of the two sets of flags.</span> + <span class='attribute'>#[<span class='ident'>inline</span>]</span> + <span class='kw'>fn</span> <span class='ident'>bitor</span>(<span class='self'>self</span>, <span class='ident'>other</span>: <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>) <span class='op'>-></span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { + <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { <span class='ident'>bits</span>: <span class='self'>self</span>.<span class='ident'>bits</span> <span class='op'>|</span> <span class='ident'>other</span>.<span class='ident'>bits</span> } + } + } + + <span class='kw'>impl</span> ::<span class='ident'>std</span>::<span class='ident'>ops</span>::<span class='ident'>BitXor</span> <span class='kw'>for</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { + <span class='kw'>type</span> <span class='ident'>Output</span> <span class='op'>=</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>; + + <span class='doccomment'>/// Returns the left flags, but with all the right flags toggled.</span> + <span class='attribute'>#[<span class='ident'>inline</span>]</span> + <span class='kw'>fn</span> <span class='ident'>bitxor</span>(<span class='self'>self</span>, <span class='ident'>other</span>: <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>) <span class='op'>-></span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { + <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { <span class='ident'>bits</span>: <span class='self'>self</span>.<span class='ident'>bits</span> <span class='op'>^</span> <span class='ident'>other</span>.<span class='ident'>bits</span> } + } + } + + <span class='kw'>impl</span> ::<span class='ident'>std</span>::<span class='ident'>ops</span>::<span class='ident'>BitAnd</span> <span class='kw'>for</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { + <span class='kw'>type</span> <span class='ident'>Output</span> <span class='op'>=</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>; + + <span class='doccomment'>/// Returns the intersection between the two sets of flags.</span> + <span class='attribute'>#[<span class='ident'>inline</span>]</span> + <span class='kw'>fn</span> <span class='ident'>bitand</span>(<span class='self'>self</span>, <span class='ident'>other</span>: <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>) <span class='op'>-></span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { + <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { <span class='ident'>bits</span>: <span class='self'>self</span>.<span class='ident'>bits</span> <span class='kw-2'>&</span> <span class='ident'>other</span>.<span class='ident'>bits</span> } + } + } + + <span class='kw'>impl</span> ::<span class='ident'>std</span>::<span class='ident'>ops</span>::<span class='ident'>Sub</span> <span class='kw'>for</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { + <span class='kw'>type</span> <span class='ident'>Output</span> <span class='op'>=</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>; + + <span class='doccomment'>/// Returns the set difference of the two sets of flags.</span> + <span class='attribute'>#[<span class='ident'>inline</span>]</span> + <span class='kw'>fn</span> <span class='ident'>sub</span>(<span class='self'>self</span>, <span class='ident'>other</span>: <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>) <span class='op'>-></span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { + <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { <span class='ident'>bits</span>: <span class='self'>self</span>.<span class='ident'>bits</span> <span class='kw-2'>&</span> <span class='op'>!</span><span class='ident'>other</span>.<span class='ident'>bits</span> } + } + } + + <span class='kw'>impl</span> ::<span class='ident'>std</span>::<span class='ident'>ops</span>::<span class='ident'>Not</span> <span class='kw'>for</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { + <span class='kw'>type</span> <span class='ident'>Output</span> <span class='op'>=</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>; + + <span class='doccomment'>/// Returns the complement of this set of flags.</span> + <span class='attribute'>#[<span class='ident'>inline</span>]</span> + <span class='kw'>fn</span> <span class='ident'>not</span>(<span class='self'>self</span>) <span class='op'>-></span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { + <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span> { <span class='ident'>bits</span>: <span class='op'>!</span><span class='self'>self</span>.<span class='ident'>bits</span> } <span class='kw-2'>&</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>::<span class='ident'>all</span>() + } + } + }; + ($(<span class='attribute'>#[<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>attr</span>:<span class='ident'>meta</span>]</span>)<span class='op'>*</span> <span class='ident'>flags</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>:<span class='ident'>ident</span>: <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>T</span>:<span class='ident'>ty</span> { + $($(<span class='attribute'>#[<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>Flag_attr</span>:<span class='ident'>meta</span>]</span>)<span class='op'>*</span> <span class='kw'>const</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>Flag</span>:<span class='ident'>ident</span> <span class='op'>=</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>value</span>:<span class='ident'>expr</span>),<span class='op'>+</span>, + }) <span class='op'>=></span> { + <span class='macro'>bitflags</span><span class='macro'>!</span> { + $(<span class='attribute'>#[<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>attr</span>]</span>)<span class='op'>*</span> + <span class='ident'>flags</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>BitFlags</span>: <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>T</span> { + $($(<span class='attribute'>#[<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>Flag_attr</span>]</span>)<span class='op'>*</span> <span class='kw'>const</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>Flag</span> <span class='op'>=</span> <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>value</span>),<span class='op'>+</span> + } + } + }; +} +</pre> +<div class='docblock'><p>The <code>bitflags!</code> macro generates a <code>struct</code> that holds a set of C-style +bitmask flags. It is useful for creating typesafe wrappers for C APIs.</p> + +<p>The flags should only be defined for integer types, otherwise unexpected +type errors may occur at compile time.</p> + +<h1 id="example" class='section-header'><a + href="#example">Example</a></h1><pre class='rust rust-example-rendered'> +<span class='attribute'>#[<span class='ident'>macro_use</span>]</span> +<span class='kw'>extern</span> <span class='kw'>crate</span> <span class='ident'>bitflags</span>; + +<span class='macro'>bitflags</span><span class='macro'>!</span> { + <span class='ident'>flags</span> <span class='ident'>Flags</span>: <span class='ident'>u32</span> { + <span class='kw'>const</span> <span class='ident'>FLAG_A</span> <span class='op'>=</span> <span class='number'>0b00000001</span>, + <span class='kw'>const</span> <span class='ident'>FLAG_B</span> <span class='op'>=</span> <span class='number'>0b00000010</span>, + <span class='kw'>const</span> <span class='ident'>FLAG_C</span> <span class='op'>=</span> <span class='number'>0b00000100</span>, + <span class='kw'>const</span> <span class='ident'>FLAG_ABC</span> <span class='op'>=</span> <span class='ident'>FLAG_A</span>.<span class='ident'>bits</span> + <span class='op'>|</span> <span class='ident'>FLAG_B</span>.<span class='ident'>bits</span> + <span class='op'>|</span> <span class='ident'>FLAG_C</span>.<span class='ident'>bits</span>, + } +} + +<span class='kw'>fn</span> <span class='ident'>main</span>() { + <span class='kw'>let</span> <span class='ident'>e1</span> <span class='op'>=</span> <span class='ident'>FLAG_A</span> <span class='op'>|</span> <span class='ident'>FLAG_C</span>; + <span class='kw'>let</span> <span class='ident'>e2</span> <span class='op'>=</span> <span class='ident'>FLAG_B</span> <span class='op'>|</span> <span class='ident'>FLAG_C</span>; + <span class='macro'>assert</span><span class='macro'>!</span>((<span class='ident'>e1</span> <span class='op'>|</span> <span class='ident'>e2</span>) <span class='op'>==</span> <span class='ident'>FLAG_ABC</span>); <span class='comment'>// union</span> + <span class='macro'>assert</span><span class='macro'>!</span>((<span class='ident'>e1</span> <span class='kw-2'>&</span> <span class='ident'>e2</span>) <span class='op'>==</span> <span class='ident'>FLAG_C</span>); <span class='comment'>// intersection</span> + <span class='macro'>assert</span><span class='macro'>!</span>((<span class='ident'>e1</span> <span class='op'>-</span> <span class='ident'>e2</span>) <span class='op'>==</span> <span class='ident'>FLAG_A</span>); <span class='comment'>// set difference</span> + <span class='macro'>assert</span><span class='macro'>!</span>(<span class='op'>!</span><span class='ident'>e2</span> <span class='op'>==</span> <span class='ident'>FLAG_A</span>); <span class='comment'>// set complement</span> +} +</pre> + +<p>The generated <code>struct</code>s can also be extended with type and trait +implementations:</p> +<pre class='rust rust-example-rendered'> +<span class='attribute'>#[<span class='ident'>macro_use</span>]</span> +<span class='kw'>extern</span> <span class='kw'>crate</span> <span class='ident'>bitflags</span>; + +<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>fmt</span>; + +<span class='macro'>bitflags</span><span class='macro'>!</span> { + <span class='ident'>flags</span> <span class='ident'>Flags</span>: <span class='ident'>u32</span> { + <span class='kw'>const</span> <span class='ident'>FLAG_A</span> <span class='op'>=</span> <span class='number'>0b00000001</span>, + <span class='kw'>const</span> <span class='ident'>FLAG_B</span> <span class='op'>=</span> <span class='number'>0b00000010</span>, + } +} + +<span class='kw'>impl</span> <span class='ident'>Flags</span> { + <span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>clear</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>) { + <span class='self'>self</span>.<span class='ident'>bits</span> <span class='op'>=</span> <span class='number'>0</span>; <span class='comment'>// The `bits` field can be accessed from within the</span> + <span class='comment'>// same module where the `bitflags!` macro was invoked.</span> + } +} + +<span class='kw'>impl</span> <span class='ident'>fmt</span>::<span class='ident'>Display</span> <span class='kw'>for</span> <span class='ident'>Flags</span> { + <span class='kw'>fn</span> <span class='ident'>fmt</span>(<span class='kw-2'>&</span><span class='self'>self</span>, <span class='ident'>f</span>: <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>fmt</span>::<span class='ident'>Formatter</span>) <span class='op'>-></span> <span class='ident'>fmt</span>::<span class='prelude-ty'>Result</span> { + <span class='macro'>write</span><span class='macro'>!</span>(<span class='ident'>f</span>, <span class='string'>"hi!"</span>) + } +} + +<span class='kw'>fn</span> <span class='ident'>main</span>() { + <span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>flags</span> <span class='op'>=</span> <span class='ident'>FLAG_A</span> <span class='op'>|</span> <span class='ident'>FLAG_B</span>; + <span class='ident'>flags</span>.<span class='ident'>clear</span>(); + <span class='macro'>assert</span><span class='macro'>!</span>(<span class='ident'>flags</span>.<span class='ident'>is_empty</span>()); + <span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{}"</span>, <span class='ident'>flags</span>), <span class='string'>"hi!"</span>); + <span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{:?}"</span>, <span class='ident'>FLAG_A</span> <span class='op'>|</span> <span class='ident'>FLAG_B</span>), <span class='string'>"Flags { bits: 0b11 }"</span>); + <span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{:?}"</span>, <span class='ident'>FLAG_B</span>), <span class='string'>"Flags { bits: 0b10 }"</span>); +} +</pre> + +<h1 id="attributes" class='section-header'><a + href="#attributes">Attributes</a></h1> +<p>Attributes can be attached to the generated <code>struct</code> by placing them +before the <code>flags</code> keyword.</p> + +<h1 id="derived-traits" class='section-header'><a + href="#derived-traits">Derived traits</a></h1> +<p>The <code>PartialEq</code> and <code>Clone</code> traits are automatically derived for the +<code>struct</code> using the <code>deriving</code> attribute. Additional traits can be derived by +providing an explicit <code>deriving</code> attribute on <code>flags</code>. The <code>Debug</code> trait is +also implemented by displaying the bits value of the internal struct.</p> + +<h1 id="operators" class='section-header'><a + href="#operators">Operators</a></h1> +<p>The following operator traits are implemented for the generated <code>struct</code>:</p> + +<ul> +<li><code>BitOr</code>: union</li> +<li><code>BitAnd</code>: intersection</li> +<li><code>BitXor</code>: toggle</li> +<li><code>Sub</code>: set difference</li> +<li><code>Not</code>: set complement</li> +</ul> + +<h1 id="methods" class='section-header'><a + href="#methods">Methods</a></h1> +<p>The following methods are defined for the generated <code>struct</code>:</p> + +<ul> +<li><code>empty</code>: an empty set of flags</li> +<li><code>all</code>: the set of all flags</li> +<li><code>bits</code>: the raw value of the flags currently stored</li> +<li><code>from_bits</code>: convert from underlying bit representation, unless that + representation contains bits that do not correspond to a flag</li> +<li><code>from_bits_truncate</code>: convert from underlying bit representation, dropping + any bits that do not correspond to flags</li> +<li><code>is_empty</code>: <code>true</code> if no flags are currently stored</li> +<li><code>is_all</code>: <code>true</code> if all flags are currently set</li> +<li><code>intersects</code>: <code>true</code> if there are flags common to both <code>self</code> and <code>other</code></li> +<li><code>contains</code>: <code>true</code> all of the flags in <code>other</code> are contained within <code>self</code></li> +<li><code>insert</code>: inserts the specified flags in-place</li> +<li><code>remove</code>: removes the specified flags in-place</li> +<li><code>toggle</code>: the specified flags will be inserted if not present, and removed + if they are.</li> +</ul> +</div></section> + <section id='search' class="content hidden"></section> + + <section class="footer"></section> + + <div id="help" class="hidden"> + <div class="shortcuts"> + <h1>Keyboard shortcuts</h1> + <dl> + <dt>?</dt> + <dd>Show this help dialog</dd> + <dt>S</dt> + <dd>Focus the search field</dd> + <dt>⇤</dt> + <dd>Move up in search results</dd> + <dt>⇥</dt> + <dd>Move down in search results</dd> + <dt>⏎</dt> + <dd>Go to active search result</dd> + </dl> + </div> + <div class="infos"> + <h1>Search tricks</h1> + <p> + Prefix searches with a type followed by a colon (e.g. + <code>fn:</code>) to restrict the search to a given type. + </p> + <p> + Accepted types are: <code>fn</code>, <code>mod</code>, + <code>struct</code>, <code>enum</code>, + <code>trait</code>, <code>typedef</code> (or + <code>tdef</code>). + </p> + <p> + Search functions by type signature (e.g. + <code>vec -> usize</code>) + </p> + </div> + </div> + + + + <script> + window.rootPath = "../"; + window.currentCrate = "bitflags"; + window.playgroundUrl = ""; + </script> + <script src="../jquery.js"></script> + <script src="../main.js"></script> + + <script async src="../search-index.js"></script> +</body> +</html>
\ No newline at end of file diff --git a/bitflags/sidebar-items.js b/bitflags/sidebar-items.js new file mode 100644 index 0000000..f37c8e5 --- /dev/null +++ b/bitflags/sidebar-items.js @@ -0,0 +1 @@ +initSidebarItems({"macro":[["bitflags!","The `bitflags!` macro generates a `struct` that holds a set of C-style bitmask flags. It is useful for creating typesafe wrappers for C APIs."]]});
\ No newline at end of file |