configbuilder_pattern_loader/feature_state_ops.rs
1use crate::FeatureState;
2
3/// Operations on [`FeatureState<T>`] — presence-driven feature gate.
4pub trait FeatureStateOps: Sized {
5 /// The inner value type when the state is enabled.
6 type Value;
7
8 /// Return `true` when the state holds an enabled value.
9 fn is_enabled(&self) -> bool;
10
11 /// Return `true` when the state is disabled.
12 fn is_disabled(&self) -> bool;
13
14 /// Convert into an `Option<Self::Value>`, discarding disabled states.
15 fn into_option(self) -> Option<Self::Value>;
16
17 /// Borrow the inner value when enabled.
18 fn as_option(&self) -> Option<&Self::Value>;
19
20 /// Map the inner value when enabled.
21 fn map<U>(self, f: impl FnOnce(Self::Value) -> U) -> FeatureState<U>;
22
23 /// Chain another state-producing operation when enabled.
24 fn and_then<U>(self, f: impl FnOnce(Self::Value) -> FeatureState<U>) -> FeatureState<U>;
25
26 /// Return the inner value or the provided default when disabled.
27 fn unwrap_or(self, default: Self::Value) -> Self::Value;
28
29 /// Return the inner value or compute one lazily when disabled.
30 fn unwrap_or_else(self, f: impl FnOnce() -> Self::Value) -> Self::Value;
31
32 /// Return the enabled value or `Self::Value::default()` when disabled.
33 fn enabled_or_default(self) -> Self::Value
34 where
35 Self::Value: Default;
36}