pub struct FeatureFlags { /* private fields */ }Implementations§
Source§impl FeatureFlags
impl FeatureFlags
pub fn new(cache: BoxedCache) -> Self
Sourcepub fn ttl(self, ttl: Duration) -> Self
pub fn ttl(self, ttl: Duration) -> Self
Override the per-entry TTL. Lower = faster propagation across replicas; higher = less cache load. Default 1 hour.
Sourcepub async fn disable(&self, name: &str)
pub async fn disable(&self, name: &str)
Globally disable the flag for everyone (overrides per-user enables for the killswitch effect).
Sourcepub async fn clear(&self, name: &str, known_user_ids: &[&str])
pub async fn clear(&self, name: &str, known_user_ids: &[&str])
Drop every record for name — global state, percentage, and
known per-user overrides for the supplied list. (We can’t
enumerate keys generically through the Cache trait, so callers
supply any user ids they want to scrub.)
Sourcepub async fn set_percentage(&self, name: &str, percent: u8)
pub async fn set_percentage(&self, name: &str, percent: u8)
Set a rollout percentage 0..=100. The flag returns true for a
stable, hashed slice of user ids — the same id falls inside the
percentage on every check, so a user doesn’t flicker between
requests.
Sourcepub async fn enable_for_user(&self, name: &str, user_id: &str)
pub async fn enable_for_user(&self, name: &str, user_id: &str)
Force-enable the flag for a specific user, regardless of global state. Useful for QA / staff dogfood.
Sourcepub async fn disable_for_user(&self, name: &str, user_id: &str)
pub async fn disable_for_user(&self, name: &str, user_id: &str)
Force-disable the flag for a specific user.
Sourcepub async fn is_enabled(&self, name: &str) -> bool
pub async fn is_enabled(&self, name: &str) -> bool
Resolve the flag globally — no per-user awareness. Returns
false when:
- the flag was explicitly disabled, OR
- the cache is empty and there’s no rollout percentage record (i.e. the flag has never been touched).
Sourcepub async fn is_enabled_for(&self, name: &str, user_id: &str) -> bool
pub async fn is_enabled_for(&self, name: &str, user_id: &str) -> bool
Resolve the flag for a specific user, considering all three modes in this order:
- Per-user override (
enable_for_user/disable_for_user). Whichever wins. - Global state (
enable/disable). If the global state isoff, that’s the answer (killswitch wins). - Percentage rollout — if set and
> 0, hash the user id and returntruewhen it falls inside the percentage. - Default
false.
Trait Implementations§
Source§impl Clone for FeatureFlags
impl Clone for FeatureFlags
Source§fn clone(&self) -> FeatureFlags
fn clone(&self) -> FeatureFlags
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for FeatureFlags
impl !UnwindSafe for FeatureFlags
impl Freeze for FeatureFlags
impl Send for FeatureFlags
impl Sync for FeatureFlags
impl Unpin for FeatureFlags
impl UnsafeUnpin for FeatureFlags
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more