Sophie

Sophie

distrib > Mageia > 6 > armv7hl > media > core-updates > by-pkgid > 564935689ab5527f955e5449ded02799 > files > 4456

rust-doc-1.19.0-1.mga6.armv7hl.rpm

<!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 `BitAndAssign` trait in crate `std`.">
    <meta name="keywords" content="rust, rustlang, rust-lang, BitAndAssign">

    <title>std::ops::BitAndAssign - Rust</title>

    <link rel="stylesheet" type="text/css" href="../../normalize.css">
    <link rel="stylesheet" type="text/css" href="../../rustdoc.css">
    <link rel="stylesheet" type="text/css" href="../../main.css">
    

    <link rel="shortcut icon" href="https://doc.rust-lang.org/favicon.ico">
    
</head>
<body class="rustdoc trait">
    <!--[if lte IE 8]>
    <div class="warning">
        This old browser is unsupported and will most likely display funky
        things.
    </div>
    <![endif]-->

    

    <nav class="sidebar">
        <a href='../../std/index.html'><img src='https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png' alt='logo' width='100'></a>
        <p class='location'>Trait BitAndAssign</p><div class="block items"><ul><li><a href="#required-methods">Required Methods</a></li><li><a href="#implementors">Implementors</a></li></ul></div><p class='location'><a href='../index.html'>std</a>::<wbr><a href='index.html'>ops</a></p><script>window.sidebarCurrent = {name: 'BitAndAssign', ty: 'trait', relpath: ''};</script><script defer src="sidebar-items.js"></script>
    </nav>

    <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">
<h1 class='fqn'><span class='in-band'>Trait <a href='../index.html'>std</a>::<wbr><a href='index.html'>ops</a>::<wbr><a class="trait" href=''>BitAndAssign</a></span><span class='out-of-band'><span class='since' title='Stable since Rust version 1.8.0'>1.8.0</span><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/core/ops.rs.html#1697-1701' title='goto source code'>[src]</a></span></h1>
<pre class='rust trait'><div class="docblock attributes">#[lang = "bitand_assign"]
</div>pub trait BitAndAssign&lt;Rhs&nbsp;=&nbsp;Self&gt; {
    fn <a href='#tymethod.bitand_assign' class='fnname'>bitand_assign</a>(&amp;mut self, rhs: Rhs);
}</pre><div class='docblock'><p>The bitwise AND assignment operator <code>&amp;=</code>.</p>

<h1 id='examples' class='section-header'><a href='#examples'>Examples</a></h1>
<p>In this example, the <code>&amp;=</code> operator is lifted to a trivial <code>Scalar</code> type.</p>

<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">ops</span>::<span class="ident">BitAndAssign</span>;

<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Debug</span>, <span class="ident">PartialEq</span>)]</span>
<span class="kw">struct</span> <span class="ident">Scalar</span>(<span class="ident">bool</span>);

<span class="kw">impl</span> <span class="ident">BitAndAssign</span> <span class="kw">for</span> <span class="ident">Scalar</span> {
    <span class="comment">// rhs is the &quot;right-hand side&quot; of the expression `a &amp;= b`</span>
    <span class="kw">fn</span> <span class="ident">bitand_assign</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="self">self</span>, <span class="ident">rhs</span>: <span class="self">Self</span>) {
        <span class="kw-2">*</span><span class="self">self</span> <span class="op">=</span> <span class="ident">Scalar</span>(<span class="self">self</span>.<span class="number">0</span> <span class="op">&amp;</span> <span class="ident">rhs</span>.<span class="number">0</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">scalar</span> <span class="op">=</span> <span class="ident">Scalar</span>(<span class="bool-val">true</span>);
    <span class="ident">scalar</span> <span class="op">&amp;=</span> <span class="ident">Scalar</span>(<span class="bool-val">true</span>);
    <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">scalar</span>, <span class="ident">Scalar</span>(<span class="bool-val">true</span>));

    <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">scalar</span> <span class="op">=</span> <span class="ident">Scalar</span>(<span class="bool-val">true</span>);
    <span class="ident">scalar</span> <span class="op">&amp;=</span> <span class="ident">Scalar</span>(<span class="bool-val">false</span>);
    <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">scalar</span>, <span class="ident">Scalar</span>(<span class="bool-val">false</span>));

    <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">scalar</span> <span class="op">=</span> <span class="ident">Scalar</span>(<span class="bool-val">false</span>);
    <span class="ident">scalar</span> <span class="op">&amp;=</span> <span class="ident">Scalar</span>(<span class="bool-val">true</span>);
    <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">scalar</span>, <span class="ident">Scalar</span>(<span class="bool-val">false</span>));

    <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">scalar</span> <span class="op">=</span> <span class="ident">Scalar</span>(<span class="bool-val">false</span>);
    <span class="ident">scalar</span> <span class="op">&amp;=</span> <span class="ident">Scalar</span>(<span class="bool-val">false</span>);
    <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">scalar</span>, <span class="ident">Scalar</span>(<span class="bool-val">false</span>));
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=use%20std%3A%3Aops%3A%3ABitAndAssign%3B%0A%0A%23%5Bderive(Debug%2C%20PartialEq)%5D%0Astruct%20Scalar(bool)%3B%0A%0Aimpl%20BitAndAssign%20for%20Scalar%20%7B%0A%20%20%20%20%2F%2F%20rhs%20is%20the%20%22right-hand%20side%22%20of%20the%20expression%20%60a%20%26%3D%20b%60%0A%20%20%20%20fn%20bitand_assign(%26mut%20self%2C%20rhs%3A%20Self)%20%7B%0A%20%20%20%20%20%20%20%20*self%20%3D%20Scalar(self.0%20%26%20rhs.0)%0A%20%20%20%20%7D%0A%7D%0A%0Afn%20main()%20%7B%0A%20%20%20%20let%20mut%20scalar%20%3D%20Scalar(true)%3B%0A%20%20%20%20scalar%20%26%3D%20Scalar(true)%3B%0A%20%20%20%20assert_eq!(scalar%2C%20Scalar(true))%3B%0A%0A%20%20%20%20let%20mut%20scalar%20%3D%20Scalar(true)%3B%0A%20%20%20%20scalar%20%26%3D%20Scalar(false)%3B%0A%20%20%20%20assert_eq!(scalar%2C%20Scalar(false))%3B%0A%0A%20%20%20%20let%20mut%20scalar%20%3D%20Scalar(false)%3B%0A%20%20%20%20scalar%20%26%3D%20Scalar(true)%3B%0A%20%20%20%20assert_eq!(scalar%2C%20Scalar(false))%3B%0A%0A%20%20%20%20let%20mut%20scalar%20%3D%20Scalar(false)%3B%0A%20%20%20%20scalar%20%26%3D%20Scalar(false)%3B%0A%20%20%20%20assert_eq!(scalar%2C%20Scalar(false))%3B%0A%7D%0A">Run</a></pre>

<p>In this example, the <code>BitAndAssign</code> trait is implemented for a
<code>BooleanVector</code> struct.</p>

<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">ops</span>::<span class="ident">BitAndAssign</span>;

<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Debug</span>, <span class="ident">PartialEq</span>)]</span>
<span class="kw">struct</span> <span class="ident">BooleanVector</span>(<span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">bool</span><span class="op">&gt;</span>);

<span class="kw">impl</span> <span class="ident">BitAndAssign</span> <span class="kw">for</span> <span class="ident">BooleanVector</span> {
    <span class="comment">// rhs is the &quot;right-hand side&quot; of the expression `a &amp;= b`</span>
    <span class="kw">fn</span> <span class="ident">bitand_assign</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="self">self</span>, <span class="ident">rhs</span>: <span class="self">Self</span>) {
        <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="self">self</span>.<span class="number">0</span>.<span class="ident">len</span>(), <span class="ident">rhs</span>.<span class="number">0</span>.<span class="ident">len</span>());
        <span class="kw-2">*</span><span class="self">self</span> <span class="op">=</span> <span class="ident">BooleanVector</span>(<span class="self">self</span>.<span class="number">0</span>
                                  .<span class="ident">iter</span>()
                                  .<span class="ident">zip</span>(<span class="ident">rhs</span>.<span class="number">0</span>.<span class="ident">iter</span>())
                                  .<span class="ident">map</span>(<span class="op">|</span>(<span class="ident">x</span>, <span class="ident">y</span>)<span class="op">|</span> <span class="kw-2">*</span><span class="ident">x</span> <span class="op">&amp;&amp;</span> <span class="kw-2">*</span><span class="ident">y</span>)
                                  .<span class="ident">collect</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">bv</span> <span class="op">=</span> <span class="ident">BooleanVector</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="bool-val">true</span>, <span class="bool-val">true</span>, <span class="bool-val">false</span>, <span class="bool-val">false</span>]);
    <span class="ident">bv</span> <span class="op">&amp;=</span> <span class="ident">BooleanVector</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="bool-val">true</span>, <span class="bool-val">false</span>, <span class="bool-val">true</span>, <span class="bool-val">false</span>]);
    <span class="kw">let</span> <span class="ident">expected</span> <span class="op">=</span> <span class="ident">BooleanVector</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="bool-val">true</span>, <span class="bool-val">false</span>, <span class="bool-val">false</span>, <span class="bool-val">false</span>]);
    <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">bv</span>, <span class="ident">expected</span>);
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=use%20std%3A%3Aops%3A%3ABitAndAssign%3B%0A%0A%23%5Bderive(Debug%2C%20PartialEq)%5D%0Astruct%20BooleanVector(Vec%3Cbool%3E)%3B%0A%0Aimpl%20BitAndAssign%20for%20BooleanVector%20%7B%0A%20%20%20%20%2F%2F%20rhs%20is%20the%20%22right-hand%20side%22%20of%20the%20expression%20%60a%20%26%3D%20b%60%0A%20%20%20%20fn%20bitand_assign(%26mut%20self%2C%20rhs%3A%20Self)%20%7B%0A%20%20%20%20%20%20%20%20assert_eq!(self.0.len()%2C%20rhs.0.len())%3B%0A%20%20%20%20%20%20%20%20*self%20%3D%20BooleanVector(self.0%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.iter()%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.zip(rhs.0.iter())%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.map(%7C(x%2C%20y)%7C%20*x%20%26%26%20*y)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.collect())%3B%0A%20%20%20%20%7D%0A%7D%0A%0Afn%20main()%20%7B%0A%20%20%20%20let%20mut%20bv%20%3D%20BooleanVector(vec!%5Btrue%2C%20true%2C%20false%2C%20false%5D)%3B%0A%20%20%20%20bv%20%26%3D%20BooleanVector(vec!%5Btrue%2C%20false%2C%20true%2C%20false%5D)%3B%0A%20%20%20%20let%20expected%20%3D%20BooleanVector(vec!%5Btrue%2C%20false%2C%20false%2C%20false%5D)%3B%0A%20%20%20%20assert_eq!(bv%2C%20expected)%3B%0A%7D%0A">Run</a></pre>
</div>
            <h2 id='required-methods'>Required Methods</h2>
            <div class='methods'>
        <h3 id='tymethod.bitand_assign' class='method'><span id='bitand_assign.v' class='invisible'><code>fn <a href='#tymethod.bitand_assign' class='fnname'>bitand_assign</a>(&amp;mut self, rhs: Rhs)</code></span></h3><div class='docblock'><p>The method for the <code>&amp;=</code> operator</p>
</div></div>
        <h2 id='implementors'>Implementors</h2>
        <ul class='item-list' id='implementors-list'>
    <li><code>impl BitAndAssign&lt;<a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.i64.html">i64</a>&gt;&gt; for <a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.i64.html">i64</a>&gt;</code></li>
<li><code>impl BitAndAssign&lt;<a class="primitive" href="../primitive.u8.html">u8</a>&gt; for <a class="primitive" href="../primitive.u8.html">u8</a></code></li>
<li><code>impl BitAndAssign&lt;<a class="primitive" href="../primitive.i32.html">i32</a>&gt; for <a class="primitive" href="../primitive.i32.html">i32</a></code></li>
<li><code>impl BitAndAssign&lt;<a class="primitive" href="../primitive.u32.html">u32</a>&gt; for <a class="primitive" href="../primitive.u32.html">u32</a></code></li>
<li><code>impl BitAndAssign&lt;<a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.u128.html">u128</a>&gt;&gt; for <a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.u128.html">u128</a>&gt;</code></li>
<li><code>impl BitAndAssign&lt;<a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.i32.html">i32</a>&gt;&gt; for <a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.i32.html">i32</a>&gt;</code></li>
<li><code>impl BitAndAssign&lt;<a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.i16.html">i16</a>&gt;&gt; for <a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.i16.html">i16</a>&gt;</code></li>
<li><code>impl BitAndAssign&lt;<a class="primitive" href="../primitive.u128.html">u128</a>&gt; for <a class="primitive" href="../primitive.u128.html">u128</a></code></li>
<li><code>impl BitAndAssign&lt;<a class="primitive" href="../primitive.i128.html">i128</a>&gt; for <a class="primitive" href="../primitive.i128.html">i128</a></code></li>
<li><code>impl BitAndAssign&lt;<a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.u16.html">u16</a>&gt;&gt; for <a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.u16.html">u16</a>&gt;</code></li>
<li><code>impl BitAndAssign&lt;<a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.u32.html">u32</a>&gt;&gt; for <a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.u32.html">u32</a>&gt;</code></li>
<li><code>impl BitAndAssign&lt;<a class="primitive" href="../primitive.i16.html">i16</a>&gt; for <a class="primitive" href="../primitive.i16.html">i16</a></code></li>
<li><code>impl BitAndAssign&lt;<a class="primitive" href="../primitive.i64.html">i64</a>&gt; for <a class="primitive" href="../primitive.i64.html">i64</a></code></li>
<li><code>impl BitAndAssign&lt;<a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.u64.html">u64</a>&gt;&gt; for <a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.u64.html">u64</a>&gt;</code></li>
<li><code>impl BitAndAssign&lt;<a class="primitive" href="../primitive.usize.html">usize</a>&gt; for <a class="primitive" href="../primitive.usize.html">usize</a></code></li>
<li><code>impl BitAndAssign&lt;<a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.u8.html">u8</a>&gt;&gt; for <a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.u8.html">u8</a>&gt;</code></li>
<li><code>impl BitAndAssign&lt;<a class="primitive" href="../primitive.u16.html">u16</a>&gt; for <a class="primitive" href="../primitive.u16.html">u16</a></code></li>
<li><code>impl BitAndAssign&lt;<a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.i8.html">i8</a>&gt;&gt; for <a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.i8.html">i8</a>&gt;</code></li>
<li><code>impl BitAndAssign&lt;<a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.usize.html">usize</a>&gt;&gt; for <a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.usize.html">usize</a>&gt;</code></li>
<li><code>impl BitAndAssign&lt;<a class="primitive" href="../primitive.bool.html">bool</a>&gt; for <a class="primitive" href="../primitive.bool.html">bool</a></code></li>
<li><code>impl BitAndAssign&lt;<a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.isize.html">isize</a>&gt;&gt; for <a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.isize.html">isize</a>&gt;</code></li>
<li><code>impl BitAndAssign&lt;<a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.i128.html">i128</a>&gt;&gt; for <a class="struct" href="../../std/num/struct.Wrapping.html" title="struct std::num::Wrapping">Wrapping</a>&lt;<a class="primitive" href="../primitive.i128.html">i128</a>&gt;</code></li>
<li><code>impl BitAndAssign&lt;<a class="primitive" href="../primitive.u64.html">u64</a>&gt; for <a class="primitive" href="../primitive.u64.html">u64</a></code></li>
<li><code>impl BitAndAssign&lt;<a class="primitive" href="../primitive.i8.html">i8</a>&gt; for <a class="primitive" href="../primitive.i8.html">i8</a></code></li>
<li><code>impl BitAndAssign&lt;<a class="primitive" href="../primitive.isize.html">isize</a>&gt; for <a class="primitive" href="../primitive.isize.html">isize</a></code></li>
</ul><script type="text/javascript" async
                         src="../../implementors/core/ops/trait.BitAndAssign.js">
                 </script></section>
    <section id='search' class="content hidden"></section>

    <section class="footer"></section>

    <aside id="help" class="hidden">
        <div>
            <h1 class="hidden">Help</h1>

            <div class="shortcuts">
                <h2>Keyboard Shortcuts</h2>

                <dl>
                    <dt>?</dt>
                    <dd>Show this help dialog</dd>
                    <dt>S</dt>
                    <dd>Focus the search field</dd>
                    <dt>&larrb;</dt>
                    <dd>Move up in search results</dd>
                    <dt>&rarrb;</dt>
                    <dd>Move down in search results</dd>
                    <dt>&#9166;</dt>
                    <dd>Go to active search result</dd>
                    <dt>+</dt>
                    <dd>Collapse/expand all sections</dd>
                </dl>
            </div>

            <div class="infos">
                <h2>Search Tricks</h2>

                <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>type</code>, <code>macro</code>,
                    and <code>const</code>.
                </p>

                <p>
                    Search functions by type signature (e.g.
                    <code>vec -> usize</code> or <code>* -> vec</code>)
                </p>
            </div>
        </div>
    </aside>

    

    <script>
        window.rootPath = "../../";
        window.currentCrate = "std";
    </script>
    <script src="../../main.js"></script>
    <script defer src="../../search-index.js"></script>
</body>
</html>