{"id":22281765,"url":"https://github.com/meithecatte/enumflags2","last_synced_at":"2025-10-23T23:11:11.869Z","repository":{"id":41394769,"uuid":"167553735","full_name":"meithecatte/enumflags2","owner":"meithecatte","description":"Rust library for typesystem-assisted bitflags.","archived":false,"fork":false,"pushed_at":"2025-01-17T05:19:21.000Z","size":401,"stargazers_count":120,"open_issues_count":10,"forks_count":20,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-03T01:14:35.913Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/meithecatte.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-01-25T13:42:22.000Z","updated_at":"2025-05-02T18:42:42.000Z","dependencies_parsed_at":"2024-01-27T23:31:09.448Z","dependency_job_id":"ea77c0d0-30dc-44c3-93e3-0bcfdd516e0f","html_url":"https://github.com/meithecatte/enumflags2","commit_stats":{"total_commits":296,"total_committers":20,"mean_commits":14.8,"dds":"0.45608108108108103","last_synced_commit":"8205d5ba03ccc9ccb7407693440f8e47f8ceeeb4"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meithecatte%2Fenumflags2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meithecatte%2Fenumflags2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meithecatte%2Fenumflags2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meithecatte%2Fenumflags2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meithecatte","download_url":"https://codeload.github.com/meithecatte/enumflags2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254042565,"owners_count":22004905,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-03T16:21:45.562Z","updated_at":"2025-10-23T23:11:06.833Z","avatar_url":"https://github.com/meithecatte.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE-MIT)\n[![LICENSE](https://img.shields.io/badge/license-apache-blue.svg)](LICENSE-APACHE)\n[![Documentation](https://docs.rs/enumflags2/badge.svg)](https://docs.rs/enumflags2)\n[![Crates.io Version](https://img.shields.io/crates/v/enumflags2.svg)](https://crates.io/crates/enumflags2)\n\n# Enumflags\n\n`enumflags2` implements the classic bitflags datastructure. Annotate an enum\nwith `#[bitflags]`, and `BitFlags\u003cYourEnum\u003e` will be able to hold arbitrary combinations\nof your enum within the space of a single integer.\n\nUnlike other crates, `enumflags2` makes the type-level distinction between\na single flag (`YourEnum`) and a set of flags (`BitFlags\u003cYourEnum\u003e`).\nThis allows idiomatic handling of bitflags, such as with `match` and `iter`.\n\n## Features\n\n- [x] Uses enums to represent individual flags\u0026mdash;a set of flags is a separate type from a single flag.\n- [x] Automatically chooses a free bit when you don't specify.\n- [x] Detects incorrect BitFlags at compile time.\n- [x] Has a similar API compared to the popular [bitflags](https://crates.io/crates/bitflags) crate.\n- [x] Does not expose the generated types explicity. The user interacts exclusively with `struct BitFlags\u003cEnum\u003e;`.\n- [x] The debug formatter prints the binary flag value as well as the flag enums: `BitFlags(0b1111, [A, B, C, D])`.\n- [x] Optional support for serialization with the [`serde`](https://serde.rs/) feature flag.\n\n## Example\n\n```rust\nuse enumflags2::{bitflags, make_bitflags, BitFlags};\n\n#[bitflags]\n#[repr(u8)]\n#[derive(Copy, Clone, Debug, PartialEq)]\nenum Test {\n    A = 0b0001,\n    B = 0b0010,\n    C, // unspecified variants pick unused bits automatically\n    D = 0b1000,\n}\n\n// Flags can be combined with |, this creates a BitFlags of your type:\nlet a_b: BitFlags\u003cTest\u003e = Test::A | Test::B;\nlet a_c = Test::A | Test::C;\nlet b_c_d = make_bitflags!(Test::{B | C | D});\n\n// The debug output lets you inspect both the numeric value and\n// the actual flags:\nassert_eq!(format!(\"{:?}\", a_b), \"BitFlags\u003cTest\u003e(0b11, A | B)\");\n\n// But if you'd rather see only one of those, that's available too:\nassert_eq!(format!(\"{}\", a_b), \"A | B\");\nassert_eq!(format!(\"{:04b}\", a_b), \"0011\");\n\n// Iterate over the flags like a normal set\nassert_eq!(a_b.iter().collect::\u003cVec\u003c_\u003e\u003e(), \u0026[Test::A, Test::B]);\n\n// Query the contents with contains and intersects\nassert!(a_b.contains(Test::A));\nassert!(b_c_d.contains(Test::B | Test::C));\nassert!(!(b_c_d.contains(a_b)));\n\nassert!(a_b.intersects(a_c));\nassert!(!(a_b.intersects(Test::C | Test::D)));\n```\n\n## Optional Feature Flags\n\n- [`serde`](https://serde.rs/) implements `Serialize` and `Deserialize`\n  for `BitFlags\u003cT\u003e`.\n- `std` implements `std::error::Error` for `FromBitsError`.\n\n## `const fn`-compatible APIs\n\n**Background:** The subset of `const fn` features currently stabilized is pretty limited.\nMost notably, [const traits are still at the RFC stage][const-trait-rfc],\nwhich makes it impossible to use any overloaded operators in a const\ncontext.\n\n**Naming convention:** If a separate, more limited function is provided\nfor usage in a `const fn`, the name is suffixed with `_c`.\n\nApart from functions whose name ends with `_c`, the [`make_bitflags!`] macro\nis often useful for many `const` and `const fn` usecases.\n\n**Blanket implementations:** If you attempt to write a `const fn` ranging\nover `T: BitFlag`, you will be met with an error explaining that currently,\nthe only allowed trait bound for a `const fn` is `?Sized`. You will probably\nwant to write a separate implementation for `BitFlags\u003cT, u8\u003e`,\n`BitFlags\u003cT, u16\u003e`, etc — best accomplished by a simple macro.\n\n**Documentation considerations:** The strategy described above is often used\nby `enumflags2` itself. To avoid clutter in the auto-generated documentation,\nthe implementations for widths other than `u8` are marked with `#[doc(hidden)]`.\n\n## Customizing `Default`\n\nBy default, creating an instance of `BitFlags\u003cT\u003e` with `Default` will result in an empty\nset. If that's undesirable, you may customize this:\n\n```rust\n#[bitflags(default = B | C)]\n#[repr(u8)]\n#[derive(Copy, Clone, Debug, PartialEq)]\nenum Test {\n    A = 0b0001,\n    B = 0b0010,\n    C = 0b0100,\n    D = 0b1000,\n}\n\nassert_eq!(BitFlags::default(), Test::B | Test::C);\n```\n\n[const-trait-rfc]: https://github.com/rust-lang/rfcs/pull/2632\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeithecatte%2Fenumflags2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeithecatte%2Fenumflags2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeithecatte%2Fenumflags2/lists"}