1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
//! # 🎚 Feature toggle API
//!
//! This API lets you define your own feature toggles, and read them from a module.
//!
//! Feature toggles need to be declared in the `Cargo.toml` of your module, in a metadata section
//! specific to Ark. For instance, this allows declaring a feature toggle called `developer-mode`,
//! that's defaulting to false, with a small description that will used for display in the Ark
//! client.
//!
//! ```toml
//! [package.metadata.ark.feature-toggles.developer-mode]
//! default = false
//! description = "this is the description that will be shown in the Ark client's UI"
//! ````
//!
//! Feature toggle names must start with an ASCII letter. Other characters may include ASCII
//! alphanumericals or dashes or underscores.
//!
//! To read the value of a specific feature toggle, use the `get()` function provided by this
//! module.
//!
//! Example:
//!
//! ```rust,no_run
//! ark::require_feature_toggle_api!();
//!
//! fn myfunc() {
//! let is_set: bool = ark::feature_toggle::get("my-feature-toggle");
//! }
//! ```
use crate::ffi::feature_toggle_v0 as ffi;
#[doc(hidden)]
pub use ffi::API as FFI_API;
/// Reads the value for a feature toggle predefined in the package's metadata.
///
/// Panics if the feature toggle identifier hasn't been declared in the module's `Cargo.toml`.
pub fn get(id: &'static str) -> bool {
ffi::get_feature_toggle(id) == ffi::FeatureToggleValue::Enabled
}