{"id":28962752,"url":"https://github.com/sam0x17/bit-flags","last_synced_at":"2025-06-24T03:11:59.586Z","repository":{"id":300702856,"uuid":"1005825294","full_name":"sam0x17/bit-flags","owner":"sam0x17","description":"A Rust crate that provides an easy-to-use Flags trait that makes custom bitflag enums easier to implement in Rust","archived":false,"fork":false,"pushed_at":"2025-06-23T06:27:35.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-23T06:37:45.414Z","etag":null,"topics":["bitflag","bitflags","crate","enum","rust-lang"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sam0x17.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2025-06-20T22:26:26.000Z","updated_at":"2025-06-23T06:27:38.000Z","dependencies_parsed_at":"2025-06-23T06:37:48.036Z","dependency_job_id":"e9556a87-3493-4017-8c7c-24cef3833453","html_url":"https://github.com/sam0x17/bit-flags","commit_stats":null,"previous_names":["sam0x17/bit-flags"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sam0x17/bit-flags","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sam0x17%2Fbit-flags","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sam0x17%2Fbit-flags/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sam0x17%2Fbit-flags/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sam0x17%2Fbit-flags/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sam0x17","download_url":"https://codeload.github.com/sam0x17/bit-flags/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sam0x17%2Fbit-flags/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261595784,"owners_count":23182249,"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":["bitflag","bitflags","crate","enum","rust-lang"],"created_at":"2025-06-24T03:11:59.000Z","updated_at":"2025-06-24T03:11:59.568Z","avatar_url":"https://github.com/sam0x17.png","language":"Rust","readme":"[![Crates.io](https://img.shields.io/crates/v/bit-flags)](https://crates.io/crates/bit-flags)\n[![docs.rs](https://img.shields.io/docsrs/bit-flags?label=docs)](https://docs.rs/bit-flags/latest/bit_flags/)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/sam0x17/bit-flags/ci.yaml)](https://github.com/sam0x17/bit-flags/actions/workflows/ci.yaml?query=branch%3Amain)\n\nAllows for the easy creation of bitflag-based enums through the use of an easy-to-use `Flags`\ntrait that is auto-implemented on all types that are capable of stable bit-twiddling.\n\nThe Flags trait is auto-implemented mplemented on types that are capable of bitwise twiddling\nas a way of turning on and off different bit-specific flags, such as `u8`, `u16`, `u32`, `u64`,\netc.\n\nTo integrate with `bit-flags`, custom enum types should implent `From\u003cT\u003e` where `T` is the type\nthat implements `bit_flags::Flags`. You can then call `has_flag`, `set_flag`, and `unset_flag`\non `T` using flags defined by the custom enum type, like so:\n\n```rust\nuse bit_flags::Flags;\n\n#[derive(Copy, Clone, Debug, PartialEq, Eq)]\nenum MyFlags {\n    Flag1 = 1 \u003c\u003c 0, // 0b00000001\n    Flag2 = 1 \u003c\u003c 1, // 0b00000010\n    Flag3 = 1 \u003c\u003c 2, // 0b00000100\n    Flag4 = 1 \u003c\u003c 3, // 0b00001000\n}\n\nimpl From\u003cMyFlags\u003e for u8 {\n    fn from(flag: MyFlags) -\u003e Self {\n        flag as u8\n    }\n}\n\nlet mut flags: u8 = MyFlags::Flag1 as u8 | MyFlags::Flag2 as u8;\nassert!(flags.has_flag(MyFlags::Flag1));\nassert!(flags.has_flag(MyFlags::Flag2));\nassert!(!flags.has_flag(MyFlags::Flag3));\nflags.set_flag(MyFlags::Flag3);\nassert!(flags.has_flag(MyFlags::Flag3));\nflags.set_flag(MyFlags::Flag1);\nassert!(flags.has_flag(MyFlags::Flag1));\nflags.unset_flag(MyFlags::Flag2);\nassert!(!flags.has_flag(MyFlags::Flag2));\n\n// You can also use the flags directly with bitwise operations:\nflags |= MyFlags::Flag4 as u8; // Set Flag4\nflags \u0026= !(MyFlags::Flag1 as u8); // Unset Flag1\nassert!(flags.has_flag(MyFlags::Flag4));\nassert!(!flags.has_flag(MyFlags::Flag1));\nassert!(flags.has_flag(MyFlags::Flag3));\nassert!(!flags.has_flag(MyFlags::Flag2));\n```\n\nYou can also use multi-byte flags:\n```rust\nuse bit_flags::Flags;\n\n#[repr(u16)]\n#[derive(Copy, Clone, Debug, PartialEq, Eq)]\n  enum MyFlags {\n      Flag1 = 1 \u003c\u003c 0,   // 0b0000000000000001\n      Flag2 = 1 \u003c\u003c 1,   // 0b0000000000000010\n      Flag3 = 1 \u003c\u003c 2,   // 0b0000000000000100\n      Flag4 = 1 \u003c\u003c 3,   // 0b0000000000001000\n      Flag5 = 1 \u003c\u003c 4,   // 0b0000000000010000\n      Flag6 = 1 \u003c\u003c 5,   // 0b0000000000100000\n      Flag7 = 1 \u003c\u003c 6,   // 0b0000000001000000\n      Flag8 = 1 \u003c\u003c 7,   // 0b0000000010000000\n      Flag9 = 1 \u003c\u003c 8,   // 0b0000000100000000\n      Flag10 = 1 \u003c\u003c 9,  // 0b0000001000000000\n      Flag11 = 1 \u003c\u003c 10, // 0b0000010000000000\n      Flag12 = 1 \u003c\u003c 11, // 0b0000100000000000\n      Flag13 = 1 \u003c\u003c 12, // 0b0001000000000000\n      Flag14 = 1 \u003c\u003c 13, // 0b0010000000000000\n      Flag15 = 1 \u003c\u003c 14, // 0b0100000000000000\n      Flag16 = 1 \u003c\u003c 15, // 0b1000000000000000\n  }\n\nimpl From\u003cMyFlags\u003e for u16 {\n   fn from(flag: MyFlags) -\u003e Self {\n       flag as u16\n   }\n}\n\nlet mut flags: u16 = MyFlags::Flag1 as u16 | MyFlags::Flag2 as u16;\nassert!(flags.has_flag(MyFlags::Flag1));\nassert!(flags.has_flag(MyFlags::Flag2));\nassert!(!flags.has_flag(MyFlags::Flag3));\n\nflags.set_flag(MyFlags::Flag15);\nassert!(flags.has_flag(MyFlags::Flag15));\nflags.unset_flag(MyFlags::Flag1);\nassert!(!flags.has_flag(MyFlags::Flag1));\nassert_eq!(flags, MyFlags::Flag2 as u16 | MyFlags::Flag15 as u16);\n ```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsam0x17%2Fbit-flags","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsam0x17%2Fbit-flags","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsam0x17%2Fbit-flags/lists"}