<!DOCTYPE html><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><metaname="generator"content="rustdoc"><metaname="description"content="A set of defined flags using a bits type as storage."><title>Flags in bitflags - Rust</title><script>if(window.location.protocol!=="file:")document.write(`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2">`)</script><linkrel="stylesheet"href="../static.files/normalize-76eba96aa4d2e634.css"><linkrel="stylesheet"href="../static.files/rustdoc-e935ef01ae1c1829.css"><metaname="rustdoc-vars"data-root-path="../"data-static-root-path="../static.files/"data-current-crate="bitflags"data-themes=""data-resource-suffix=""data-rustdoc-version="1.78.0 (9b00956e5 2024-04-29)"data-channel="1.78.0"data-search-js="search-42d8da7a6b9792c2.js"data-settings-js="settings-4313503d2e1961c2.js"><scriptsrc="../static.files/storage-4c98445ec4002617.js"></script><scriptdefersrc="sidebar-items.js"></script><scriptdefersrc="../static.files/main-12cf3b4f4f9dc36d.js"></script><noscript><linkrel="stylesheet"href="../static.files/noscript-04d5337699b92874.css"></noscript><linkrel="alternate icon"type="image/png"href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><linkrel="alternate icon"type="image/png"href="../static.files/favicon-32x32-422f7d1d52889060.png"><linkrel="icon"type="image/svg+xml"href="../static.files/favicon-2c020d218678b618.svg"></head><bodyclass="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><navclass="mobile-topbar"><buttonclass="sidebar-menu-toggle"title="show sidebar"></button></nav><navclass="sidebar"><divclass="sidebar-crate"><h2><ahref="../bitflags/index.html">bitflags</a><spanclass="version">2.5.0</span></h2></div><h2class="location"><ahref="#">Flags</a></h2><divclass="sidebar-elems"><section><h3><ahref="#required-associated-types">Required Associated Types</a></h3><ulclass="block"><li><ahref="#associatedtype.Bits">Bits</a></li></ul><h3><ahref="#required-associated-consts">Required Associated Constants</a></h3><ulclass="block"><li><ahref="#associatedconstant.FLAGS">FLAGS</a></li></ul><h3><ahref="#required-methods">Required Methods</a></h3><ulclass="block"><li><ahref="#tymethod.bits">bits</a></li><li><ahref="#tymethod.from_bits_retain">from_bits_retain</a></li></ul><h3><ahref="#provided-methods">Provided Methods</a></h3><ulclass="block"><li><ahref="#method.all">all</a></li><li><ahref="#method.complement">complement</a></li><li><ahref="#method.contains">contains</a></li><li><ahref="#method.difference">difference</a></li><li><ahref="#method.empty">empty</a></li><li><ahref="#method.from_bits">from_bits</a></li><li><ahref="#method.from_bits_truncate">from_bits_truncate</a></li><li><ahref="#method.from_name">from_name</a></li><li><ahref="#method.insert">insert</a></li><li><ahref="#method.intersection">intersection</a></li><li><ahref="#method.intersects">intersects</a></li><li><ahref="#method.is_all">is_all</a></li><li><ahref="#method.is_empty">is_empty</a></li><li><ahref="#method.iter">iter</a></li><li><ahref="#method.iter_names">iter_names</a></li><li><ahref="#method.remove">remove</a></li><li><ahref="#method.set">set</a></li><li><ahref="#method.symmetric_difference">symmetric_difference</a></li><li><ahref="#method.toggle">toggle</a></li><li><ahref="#method.union">union</a>
<main><divclass="width-limiter"><navclass="sub"><formclass="search-form"><span></span><divid="sidebar-button"tabindex="-1"><ahref="../bitflags/all.html"title="show sidebar"></a></div><inputclass="search-input"name="search"aria-label="Run search in the documentation"autocomplete="off"spellcheck="false"placeholder="Click or press ‘S’ to search, ‘?’ for more options…"type="search"><divid="help-button"tabindex="-1"><ahref="../help.html"title="help">?</a></div><divid="settings-menu"tabindex="-1"><ahref="../settings.html"title="settings"><imgwidth="22"height="22"alt="Change settings"src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><sectionid="main-content"class="content"><divclass="main-heading"><h1>Trait <ahref="index.html">bitflags</a>::<wbr><aclass="trait"href="#">Flags</a><buttonid="copy-path"title="Copy item path to clipboard"><imgsrc="../static.files/clipboard-7571035ce49a181d.svg"width="19"height="18"alt="Copy item path"></button></h1><spanclass="out-of-band"><aclass="src"href="../src/bitflags/traits.rs.html#132-315">source</a> · <buttonid="toggle-all-docs"title="collapse all docs">[<span>−</span>]</button></span></div><preclass="rust item-decl"><code>pub trait Flags: <aclass="trait"href="https://doc.rust-lang.org/1.78.0/core/marker/trait.Sized.html"title="trait core::marker::Sized">Sized</a> + 'static {
</details>}</code></pre><detailsclass="toggle top-doc"open><summaryclass="hideme"><span>Expand description</span></summary><divclass="docblock"><p>A set of defined flags using a bits type as storage.</p>
</div></details></div><h2id="required-associated-consts"class="section-header">Required Associated Constants<ahref="#required-associated-consts"class="anchor">§</a></h2><divclass="methods"><detailsclass="toggle"open><summary><sectionid="associatedconstant.FLAGS"class="method"><aclass="src rightside"href="../src/bitflags/traits.rs.html#134">source</a><h4class="code-header">const <ahref="#associatedconstant.FLAGS"class="constant">FLAGS</a>: &'static [<aclass="struct"href="struct.Flag.html"title="struct bitflags::Flag">Flag</a><Self>]</h4></section></summary><divclass="docblock"><p>The set of defined flags.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="tymethod.from_bits_retain"class="method"><aclass="src rightside"href="../src/bitflags/traits.rs.html#179">source</a><h4class="code-header">fn <ahref="#tymethod.from_bits_retain"class="fn">from_bits_retain</a>(bits: Self::<aclass="associatedtype"href="trait.Flags.html#associatedtype.Bits"title="type bitflags::Flags::Bits">Bits</a>) -> Self</h4></section></summary><divclass="docblock"><p>Convert from a bits value exactly.</p>
</div></details></div><h2id="provided-methods"class="section-header">Provided Methods<ahref="#provided-methods"class="anchor">§</a></h2><divclass="methods"><detailsclass="toggle method-toggle"open><summary><sectionid="method.empty"class="method"><aclass="src rightside"href="../src/bitflags/traits.rs.html#140-142">source</a><h4class="code-header">fn <ahref="#method.empty"class="fn">empty</a>() -> Self</h4></section></summary><divclass="docblock"><p>Get a flags value with all bits unset.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.all"class="method"><aclass="src rightside"href="../src/bitflags/traits.rs.html#145-153">source</a><h4class="code-header">fn <ahref="#method.all"class="fn">all</a>() -> Self</h4></section></summary><divclass="docblock"><p>Get a flags value with all known bits set.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.from_name"class="method"><aclass="src rightside"href="../src/bitflags/traits.rs.html#185-198">source</a><h4class="code-header">fn <ahref="#method.from_name"class="fn">from_name</a>(name: &<aclass="primitive"href="https://doc.rust-lang.org/1.78.0/core/primitive.str.html">str</a>) -><aclass="enum"href="https://doc.rust-lang.org/1.78.0/core/option/enum.Option.html"title="enum core::option::Option">Option</a><Self></h4></section></summary><divclass="docblock"><p>Get a flags value with the bits of a flag with the given name set.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.iter"class="method"><aclass="src rightside"href="../src/bitflags/traits.rs.html#204-206">source</a><h4class="code-header">fn <ahref="#method.iter"class="fn">iter</a>(&self) -><aclass="struct"href="iter/struct.Iter.html"title="struct bitflags::iter::Iter">Iter</a><Self><ahref="#"class="tooltip"data-notable-ty="Iter<Self>">ⓘ</a></h4></section></summary><divclass="docblock"><p>Yield a set of contained flags values.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.iter_names"class="method"><aclass="src rightside"href="../src/bitflags/traits.rs.html#212-214">source</a><h4class="code-header">fn <ahref="#method.iter_names"class="fn">iter_names</a>(&self) -><aclass="struct"href="iter/struct.IterNames.html"title="struct bitflags::iter::IterNames">IterNames</a><Self><ahref="#"class="tooltip"data-notable-ty="IterNames<Self>">ⓘ</a></h4></section></summary><divclass="docblock"><p>Yield a set of contained named flags values.</p>
<p>This method is like <ahref="trait.Flags.html#method.iter"title="method bitflags::Flags::iter"><code>Flags::iter</code></a>, except only yields bits in contained named flags.
Any unknown bits, or bits not corresponding to a contained flag will not be yielded.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.is_empty"class="method"><aclass="src rightside"href="../src/bitflags/traits.rs.html#217-219">source</a><h4class="code-header">fn <ahref="#method.is_empty"class="fn">is_empty</a>(&self) -><aclass="primitive"href="https://doc.rust-lang.org/1.78.0/core/primitive.bool.html">bool</a></h4></section></summary><divclass="docblock"><p>Whether all bits in this flags value are unset.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.is_all"class="method"><aclass="src rightside"href="../src/bitflags/traits.rs.html#222-226">source</a><h4class="code-header">fn <ahref="#method.is_all"class="fn">is_all</a>(&self) -><aclass="primitive"href="https://doc.rust-lang.org/1.78.0/core/primitive.bool.html">bool</a></h4></section></summary><divclass="docblock"><p>Whether all known bits in this flags value are set.</p>
Self: <aclass="trait"href="https://doc.rust-lang.org/1.78.0/core/marker/trait.Sized.html"title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><divclass="docblock"><p>Whether any set bits in a source flags value are also set in a target flags value.</p>
Self: <aclass="trait"href="https://doc.rust-lang.org/1.78.0/core/marker/trait.Sized.html"title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><divclass="docblock"><p>Whether all set bits in a source flags value are also set in a target flags value.</p>
Self: <aclass="trait"href="https://doc.rust-lang.org/1.78.0/core/marker/trait.Sized.html"title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><divclass="docblock"><p>The bitwise or (<code>|</code>) of the bits in two flags values.</p>
Self: <aclass="trait"href="https://doc.rust-lang.org/1.78.0/core/marker/trait.Sized.html"title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><divclass="docblock"><p>The intersection of a source flags value with the complement of a target flags value (<code>&!</code>).</p>
Self: <aclass="trait"href="https://doc.rust-lang.org/1.78.0/core/marker/trait.Sized.html"title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><divclass="docblock"><p>The bitwise exclusive-or (<code>^</code>) of the bits in two flags values.</p>
Self: <aclass="trait"href="https://doc.rust-lang.org/1.78.0/core/marker/trait.Sized.html"title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><divclass="docblock"><p>Call <ahref="trait.Flags.html#method.insert"title="method bitflags::Flags::insert"><code>Flags::insert</code></a> when <code>value</code> is <code>true</code> or <ahref="trait.Flags.html#method.remove"title="method bitflags::Flags::remove"><code>Flags::remove</code></a> when <code>value</code> is <code>false</code>.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.intersection"class="method"><aclass="src rightside"href="../src/bitflags/traits.rs.html#285-287">source</a><h4class="code-header">fn <ahref="#method.intersection"class="fn">intersection</a>(self, other: Self) -> Self</h4></section></summary><divclass="docblock"><p>The bitwise and (<code>&</code>) of the bits in two flags values.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.union"class="method"><aclass="src rightside"href="../src/bitflags/traits.rs.html#291-293">source</a><h4class="code-header">fn <ahref="#method.union"class="fn">union</a>(self, other: Self) -> Self</h4></section></summary><divclass="docblock"><p>The bitwise or (<code>|</code>) of the bits in two flags values.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.difference"class="method"><aclass="src rightside"href="../src/bitflags/traits.rs.html#300-302">source</a><h4class="code-header">fn <ahref="#method.difference"class="fn">difference</a>(self, other: Self) -> Self</h4></section></summary><divclass="docblock"><p>The intersection of a source flags value with the complement of a target flags value (<code>&!</code>).</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.symmetric_difference"class="method"><aclass="src rightside"href="../src/bitflags/traits.rs.html#306-308">source</a><h4class="code-header">fn <ahref="#method.symmetric_difference"class="fn">symmetric_difference</a>(self, other: Self) -> Self</h4></section></summary><divclass="docblock"><p>The bitwise exclusive-or (<code>^</code>) of the bits in two flags values.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.complement"class="method"><aclass="src rightside"href="../src/bitflags/traits.rs.html#312-314">source</a><h4class="code-header">fn <ahref="#method.complement"class="fn">complement</a>(self) -> Self</h4></section></summary><divclass="docblock"><p>The bitwise negation (<code>!</code>) of the bits in a flags value, truncating the result.</p>