flaga is a robust, thread-safe Rust library designed for managing complex feature flags, permissions, and system states using optimized bitwise arithmetic. It bridges the gap between low-level performance and high-level developer ergonomics.
flaga is polish for flag, i was thinkin about a name, but many things were taken so i sought out the polish word and ran with it
- Zero Boilerplate: Use macros to generate entire flag structures in a single line.
- Thread Safety: Built-in support for concurrent access using
ArcandRwLock. - Persistence: Built-in support for binary (
bincode) and human-readable (JSON) serialization. - Flexibility: Choose between Static (stack-allocated) and Dynamic (heap-allocated) flag descriptors.
Using the impl_flag_trait! macro, you can create a new flag type with all bitwise operations ready to go.
use flagger::impl_flag_trait;
// Create a 64-bit flag container
impl_flag_trait!(SystemFlags, u64);The FlagManager is the brain of your system. Use the builder pattern to set it up.
let manager = FlagManager::new()
.with_file_path("flags.bin")
.add_extension_flag(".rs", "AUTO_SAVE", FlagType::Binary, 0b0001);The API is designed to be intuitive and fast.
manager.add_flag("DEBUG_MODE", FlagType::Binary, 0b0001, Some("Enables verbose logging"), None)?;
// Activate the flag
manager.set_flag("DEBUG_MODE")?;
// Check the state
if manager.check_flag("DEBUG_MODE")? {
println!("Debug mode is active!");
}Execute logic automatically based on flag states without writing if/else blocks everywhere.
let trigger = FlagTrigger::new(my_flags);
trigger.trigger_if(0b0001, || {
// This closure only runs if the 1st bit is set
initiate_shutdown();
});Parse and evaluate complex boolean logic strings at runtime.
let is_allowed = parser.check_complex_pattern("!Network.Flag1 && Core.Flag0");| Module | Purpose |
|---|---|
flag |
Defines the core Flag trait for bitwise behavior. |
flag_manager |
The thread-safe coordinator for all flags. |
macros |
Code generation tools to eliminate boilerplate. |
flag_trigger |
Event-driven execution based on flag states. |
error |
Exhaustive error handling via thiserror. |
Flagger supports two modes of saving:
- Total Recall: Saves the entire manager state, including name mappings and extension logic.
- Data-Only: Saves only the raw bitmasks (perfect for minimal database storage).
This project is licensed under the MIT License - see the LICENSE file for details.