pub struct EvaluationContext {
pub targeting_key: Option<String>,
pub custom_fields: HashMap<String, EvaluationContextFieldValue>,
}
Expand description
The evaluation context provides ambient information for the purposes of flag evaluation. Contextual data may be used as the basis for targeting, including rule-based evaluation, overrides for specific subjects, or fractional flag evaluation.
The context might contain information about the end-user, the application, the host, or any other ambient data that might be useful in flag evaluation. For example, a flag system might define rules that return a specific value based on the user’s email address, locale, or the time of day. The context provides this information. The context can be optionally provided at evaluation, and mutated in before hooks.
Fields§
§targeting_key: Option<String>
The targeting key uniquely identifies the subject (end-user, or client service) of a flag evaluation. Providers may require this field for fractional flag evaluation, rules, or overrides targeting specific users. Such providers may behave unpredictably if a targeting key is not specified at flag resolution.
custom_fields: HashMap<String, EvaluationContextFieldValue>
The evaluation context MUST support the inclusion of custom fields, having keys of type string, and values of type boolean | string | number | datetime | structure.
Implementations§
Source§impl EvaluationContext
impl EvaluationContext
Sourcepub fn with_targeting_key(self, targeting_key: impl Into<String>) -> Self
pub fn with_targeting_key(self, targeting_key: impl Into<String>) -> Self
Set the targeting_key
of the evaluation context.
Sourcepub fn with_custom_field(
self,
key: impl Into<String>,
value: impl Into<EvaluationContextFieldValue>,
) -> Self
pub fn with_custom_field( self, key: impl Into<String>, value: impl Into<EvaluationContextFieldValue>, ) -> Self
Add key
and value
to the custom field of evaluation context.
Sourcepub fn add_custom_field(
&mut self,
key: impl Into<String>,
value: impl Into<EvaluationContextFieldValue>,
)
pub fn add_custom_field( &mut self, key: impl Into<String>, value: impl Into<EvaluationContextFieldValue>, )
Add key
and value
to the custom field of evaluation context.
Sourcepub fn merge_missing(&mut self, other: &Self)
pub fn merge_missing(&mut self, other: &Self)
Merge other
into self
if corresponding field is not set.
Meaning values set into self
has higher precedence.
Trait Implementations§
Source§impl Clone for EvaluationContext
impl Clone for EvaluationContext
Source§fn clone(&self) -> EvaluationContext
fn clone(&self) -> EvaluationContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more