bitflags

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

Library
Cargo
v2.13.1
1,152stars
MIT OR Apache-2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
82/100Excellent
Development Activity80
Maintenance84
Community76
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
81/100Excellent
Architecture83
Code Quality88
Innovation74
Learning Curve80

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

TypeScript
55%
Other

Cap

Team Chat · Video Conferencing

20,986

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
65
Dependency
Built with
TypeScript55%
Rust40%
Updated yesterday
Go
32%
Apache 2.0

CubeSandbox

Developer Tools · Security · AI Agents

11,247

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
83
Repo Health
88
Technical
63
Dependency
Built with
Go32%
Rust31%
C21%
Updated today
Rust
95%
MIT

Fyrox

Game Development

9,512

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
Rust95%
Updated yesterday
Go
62%
MIT

hoop

Security · Monitoring

791

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
86
Repo Health
80
Technical
66
Dependency
Built with
Go62%
Clojure20%
JavaScript10%
Updated yesterday
Rust
89%
Apache 2.0

OpenFang

AI Agents

18,120

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
54
Repo Health
73
Technical
68
Dependency
Built with
Rust89%
Updated 1 months ago
Rust
92%
MIT

OpenPencil

AI Design Tools

5,380

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
80
Repo Health
70
Technical
75
Dependency
Built with
Rust92%
Updated today

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

Search