bitflags

A Rust macro for generating ergonomic, well-defined bitflag enum types

Library
Cargo
v2.13.2
1,163 stars
MIT OR Apache-2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
79 /100 Good
Development Activity 80
Maintenance 72
Community 76
Maturity 60
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
81 /100 Excellent
Architecture 83
Code Quality 88
Innovation 74
Learning Curve 80

bitflags is a foundational Rust crate maintained by the Rust Project Developers that provides the bitflags! macro for generating flag-enum types with well-defined semantics — combining, checking, and formatting sets of boolean flags packed into an integer, similar to C’s flag-constant idiom but with type safety and derive support.

It’s widely used across the Rust ecosystem (including in the standard library’s own dependency graph and countless FFI bindings) to model C API flag constants and to build efficient, string-parseable options types, without guaranteeing that only defined bits can ever be set — a deliberate, documented tradeoff for performance and FFI compatibility.

What You Get

  • The bitflags! macro for declaring type-safe flag sets backed by an integer representation
  • Full bitwise operator support (union, intersection, complement, symmetric difference) generated automatically
  • String parsing and Display formatting for flag sets, useful for config files and debug output
  • Optional serde, arbitrary, and bytemuck trait implementations behind Cargo feature flags
  • no_std compatibility, making it usable in embedded and kernel-level Rust code
  • A documented specification (spec.md) describing the exact semantics macro-generated types follow

Common Use Cases

  • FFI bindings - model C library flag constants (e.g. file open modes, window styles) as a type-safe Rust flag set
  • Options/configuration types - build efficient, combinable option flags for library APIs (e.g. render flags, permission bits)
  • Serialization of flag sets - use the serde feature to (de)serialize flag combinations to/from JSON or other formats
  • Embedded/no_std flag registers - represent hardware or protocol flag registers in no_std environments without heap allocation

Under The Hood

Architecture - The crate is split between src/public.rs (the user-facing macro-generated API surface: operators, iteration, formatting), src/internal.rs (the underlying bit-storage implementation shared by all generated types), src/parser.rs (string parsing of flag combinations), src/traits.rs (the trait abstractions that let the macro work generically over any integer-backed flags type), and src/external.rs (optional integrations with serde, arbitrary, and bytemuck).

Tech Stack - Pure Rust (2021 edition, MSRV 1.56), no_std-compatible with zero required dependencies; serde_core, arbitrary, and bytemuck are optional dependencies gated behind matching Cargo features so the default build stays minimal, and dev-dependencies include trybuild for macro-expansion compile-fail testing.

Code Quality - Testing is unusually rigorous for a macro crate: tests/compile-fail and tests/compile-pass use trybuild to assert the macro produces correct compiler errors/successes for edge cases, alongside tests/basic.rs and a tests/smoke-test crate; a formal spec.md document specifies exact generated-type semantics, and the project maintains a CHANGELOG and SECURITY.md, signaling process maturity befitting Rust-ecosystem-critical infrastructure.

API Design - The single bitflags! { ... } macro entry point mirrors ordinary Rust struct/const syntax, so the learning curve is low for anyone already familiar with Rust enums, while advanced users can opt into derive-like feature flags (serde, bytemuck) without touching the core macro invocation — a deliberately narrow, composable API that the README explicitly scopes (‘what you can and can’t use it for’).

Used by 6 apps in this directory

Rust
54%
Other

Cap

Team Chat · Video Conferencing

22,884

Open source Loom alternative with GPU-accelerated recording, instant share links, AI summaries, and full self-hosting via Docker Compose.

View details
89
Repo Health
81
Technical
64
Dependency
Built with
Rust 54%
TypeScript 42%
Updated 4 days ago
Go
32%
Apache 2.0

CubeSandbox

AI Agents · Developer Tools · Security

12,728

Instant, concurrent, hardware-isolated MicroVM sandboxes for AI agents — E2B-API compatible, sub-60ms cold starts, and a built-in zero-trust egress proxy, all self-hostable at scale.

View details
82
Repo Health
88
Technical
63
Dependency
Built with
Go 32%
Rust 26%
C 22%
Updated 1 weeks ago
Rust
95%
MIT

Fyrox

Game Development

9,568

A production-ready 2D/3D game engine written in Rust with a built-in scene editor, physics, and hot-reloading game scripts

View details
85
Repo Health
79
Technical
68
Dependency
Built with
Rust 95%
Updated 5 days ago
Go
64%
MIT

hoop

Monitoring · Security

823

A wire-protocol gateway that enforces data masking, command blocking, approval workflows, and full session recording for engineers and AI agents accessing production infrastructure.

View details
85
Repo Health
80
Technical
64
Dependency
Built with
Go 64%
Clojure 17%
JavaScript 11%
Updated 1 weeks ago
Rust
89%
Apache 2.0

OpenFang

AI Agents

18,210

An open-source "Agent Operating System" built in Rust — a single binary providing a kernel, memory, skills, extensions, and multi-channel runtime for running AI agents, with 1,700+ tests and zero clippy warnings.

View details
52
Repo Health
73
Technical
68
Dependency
Built with
Rust 89%
Updated 3 months ago
Rust
91%
MIT

OpenPencil

AI Design Tools

6,029

An open-source, AI-native vector design tool with concurrent agent teams, design-as-code, a built-in MCP server, and multi-model intelligence — a distinct project from the similarly-named Figma-file-reading "open-pencil" editor.

View details
81
Repo Health
70
Technical
75
Dependency
Built with
Rust 91%
Updated 5 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers