pub struct FeatureContext { /* private fields */ }Expand description
Application context passed to feature flag evaluation.
Contains arbitrary key-value data used to evaluate feature flag conditions. The identity fields determine which fields are used for rollout bucketing.
Implementations§
Source§impl FeatureContext
impl FeatureContext
pub fn new() -> Self
Sourcepub fn identity_fields(&mut self, fields: Vec<&str>)
pub fn identity_fields(&mut self, fields: Vec<&str>)
Set the fields used to compute this context’s rollout identity.
Fields are sorted lexicographically before hashing. Calling this resets the cached identity value.
Sourcepub fn insert(&mut self, key: &str, value: impl Into<Value>)
pub fn insert(&mut self, key: &str, value: impl Into<Value>)
Insert a key-value pair into the context.
Sourcepub fn id(&self) -> u64
pub fn id(&self) -> u64
Compute and return this context’s rollout identity.
The result is cached and reset when identity fields or context data change. When no identity fields are set, all context keys are used (non-deterministic rollout across contexts with different keys). The id value is mostly used to id % 100 <= rollout.
Sourcepub fn bucket_id(&self, feature_name: Option<&str>) -> u64
pub fn bucket_id(&self, feature_name: Option<&str>) -> u64
The id a percentage rollout buckets this context on.
Without a feature name this is id. With one, the name is
hashed as one more identity entry in front of the identity fields, so
each feature has its own rollout population; see
FEATURE_BUCKETING_EPOCH for which features use it.