This crate is the core implementation of the feature flags (called "feattles", for short).
Its main parts are the macro [feattles!] together with the trait [Feattles]. Please refer to
the main package - feattle for more information.
Usage example
use ;
use NoPersistence;
// Declare the struct
feattles!
// Create a new instance (`NoPersistence` is just a mock for the persistence layer)
let my_feattles = new;
// Read values (note the use of `*`)
assert_eq!;
assert_eq!;
assert_eq!;
How it works
The macro will generate a struct with the given name and visibility modifier (assuming private
by default). The generated struct implements [Feattles] and also exposes one method for each
feattle.
The methods created for each feattle allow reading their current value. For example, for a
feattle is_cool: bool, there will be a method like
pub fn is_cool(&self) -> MappedRwLockReadGuard<bool>. Note the use of
[parking_lot::MappedRwLockReadGuard] because the interior of the struct is stored behind a RwLock to
control concurrent access.
A feattle is created with the syntax $key: $type [= $default]. You can use doc coments (
starting with ///) to describe nicely what they do in your system. You can use any type that
implements [FeattleValue] and optionally provide a default. If not provided, the default
will be created with Default::default().
Updating values
This crate only disposes of low-level methods to load current feattles with [Feattles::reload()]
and update their values with [Feattles::update()]. Please look for the crates
feattle-sync and
feattle-ui for higher-level functionalities.
Limitations
Due to some restrictions on how the macro is written, you can only use [feattles!] once per
module. For example, the following does not compile:
use feattle_core::feattles;
feattles! { struct A { } }
feattles! { struct B { } }
You can work around this limitation by creating a sub-module and then re-exporting the generated
struct. Note the use of pub struct in the second case.
use feattles;
feattles!
use B;
Optional features
- uuid: will add support for [
uuid::Uuid].