Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
benches/ | 25-Apr-2025 | - | 97 | 83 | ||
examples/ | 25-Apr-2025 | - | 271 | 184 | ||
patches/ | 25-Apr-2025 | - | 30 | 25 | ||
src/ | 25-Apr-2025 | - | 5,021 | 3,414 | ||
.cargo-checksum.json | D | 25-Apr-2025 | 4.6 KiB | 1 | 1 | |
Android.bp | D | 25-Apr-2025 | 990 | 38 | 33 | |
CHANGELOG.md | D | 25-Apr-2025 | 24.2 KiB | 554 | 378 | |
CODE_OF_CONDUCT.md | D | 25-Apr-2025 | 3.1 KiB | 73 | 55 | |
CONTRIBUTING.md | D | 25-Apr-2025 | 385 | 10 | 6 | |
Cargo.lock | D | 25-Apr-2025 | 9.9 KiB | 384 | 339 | |
Cargo.toml | D | 25-Apr-2025 | 1.9 KiB | 97 | 80 | |
LICENSE | D | 25-Apr-2025 | 10.6 KiB | 202 | 169 | |
LICENSE-APACHE | D | 25-Apr-2025 | 10.6 KiB | 202 | 169 | |
LICENSE-MIT | D | 25-Apr-2025 | 1 KiB | 26 | 22 | |
METADATA | D | 25-Apr-2025 | 398 | 18 | 17 | |
MODULE_LICENSE_APACHE2 | D | 25-Apr-2025 | 0 | |||
README.md | D | 25-Apr-2025 | 2.4 KiB | 78 | 57 | |
SECURITY.md | D | 25-Apr-2025 | 690 | 14 | 7 | |
TEST_MAPPING | D | 25-Apr-2025 | 1.7 KiB | 80 | 79 | |
cargo_embargo.json | D | 25-Apr-2025 | 227 | 14 | 13 | |
rules.mk | D | 25-Apr-2025 | 565 | 18 | 11 | |
spec.md | D | 25-Apr-2025 | 10.3 KiB | 553 | 360 |
README.md
1bitflags 2======== 3 4[](https://github.com/bitflags/bitflags/actions) 5[](https://crates.io/crates/bitflags) 6[](https://docs.rs/bitflags) 7 8 9`bitflags` generates flags enums with well-defined semantics and ergonomic end-user APIs. 10 11You can use `bitflags` to: 12 13- provide more user-friendly bindings to C APIs where flags may or may not be fully known in advance. 14- generate efficient options types with string parsing and formatting support. 15 16You can't use `bitflags` to: 17 18- guarantee only bits corresponding to defined flags will ever be set. `bitflags` allows access to the underlying bits type so arbitrary bits may be set. 19- define bitfields. `bitflags` only generates types where set bits denote the presence of some combination of flags. 20 21- [Documentation](https://docs.rs/bitflags) 22- [Specification](https://github.com/bitflags/bitflags/blob/main/spec.md) 23- [Release notes](https://github.com/bitflags/bitflags/releases) 24 25## Usage 26 27Add this to your `Cargo.toml`: 28 29```toml 30[dependencies] 31bitflags = "2.6.0" 32``` 33 34and this to your source code: 35 36```rust 37use bitflags::bitflags; 38``` 39 40## Example 41 42Generate a flags structure: 43 44```rust 45use bitflags::bitflags; 46 47// The `bitflags!` macro generates `struct`s that manage a set of flags. 48bitflags! { 49 /// Represents a set of flags. 50 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 51 struct Flags: u32 { 52 /// The value `A`, at bit position `0`. 53 const A = 0b00000001; 54 /// The value `B`, at bit position `1`. 55 const B = 0b00000010; 56 /// The value `C`, at bit position `2`. 57 const C = 0b00000100; 58 59 /// The combination of `A`, `B`, and `C`. 60 const ABC = Self::A.bits() | Self::B.bits() | Self::C.bits(); 61 } 62} 63 64fn main() { 65 let e1 = Flags::A | Flags::C; 66 let e2 = Flags::B | Flags::C; 67 assert_eq!((e1 | e2), Flags::ABC); // union 68 assert_eq!((e1 & e2), Flags::C); // intersection 69 assert_eq!((e1 - e2), Flags::A); // set difference 70 assert_eq!(!e2, Flags::A); // set complement 71} 72``` 73 74## Rust Version Support 75 76The minimum supported Rust version is documented in the `Cargo.toml` file. 77This may be bumped in minor releases as necessary. 78