growthbook_sdk_rust/feature/
feature_rule_force.rs

1use crate::condition::use_case::ConditionsMatchesAttributes;
2use crate::coverage::model::Coverage;
3use crate::dto::GrowthBookFeatureRuleForce;
4use crate::extensions::FindGrowthBookAttribute;
5use crate::filter::use_case::Filter;
6use crate::model_private::FeatureResult;
7use crate::model_public::GrowthBookAttribute;
8
9impl GrowthBookFeatureRuleForce {
10    pub fn get_match_value(
11        &self,
12        feature_name: &str,
13        user_attributes: &Vec<GrowthBookAttribute>,
14    ) -> Option<FeatureResult> {
15        if let Some(filters) = &self.filters {
16            let hash_attribute = self.get_fallback_attribute();
17            if Filter::is_filtered_out(filters, &hash_attribute, user_attributes) {
18                return None;
19            }
20        }
21
22        if let Some(feature_attributes) = self.conditions() {
23            if feature_attributes.matches(user_attributes) {
24                self.check_range_or_force(feature_name, user_attributes)
25            } else {
26                None
27            }
28        } else {
29            self.check_range_or_force(feature_name, user_attributes)
30        }
31    }
32
33    fn check_range_or_force(
34        &self,
35        feature_name: &str,
36        user_attributes: &Vec<GrowthBookAttribute>,
37    ) -> Option<FeatureResult> {
38        if let Some(range) = self.range() {
39            let fallback_attribute = self.get_fallback_attribute();
40            if let Some(user_value) = user_attributes.find_value(&fallback_attribute) {
41                let seed = self.seed.clone().unwrap_or(feature_name.to_string());
42                Coverage::check(&user_value, None, Some(range), &seed, self.hash_version, self.force.clone())
43            } else {
44                None
45            }
46        } else {
47            Some(FeatureResult::force(self.force.clone()))
48        }
49    }
50}