pub mod feature_rule_experiment;
pub mod feature_rule_force;
mod feature_rule_parent;
pub mod feature_rule_rollout;
pub mod use_case;
use crate::extensions::{non_empty, truthy, FindGrowthBookAttribute};
use crate::model_public::{GrowthBookAttribute, GrowthBookAttributeValue};
pub(crate) fn resolve_hash_attribute(
hash_attribute: &Option<String>,
fallback_attribute: &Option<String>,
fallback_allowed: bool,
user_attributes: &Vec<GrowthBookAttribute>,
) -> Option<(String, GrowthBookAttributeValue)> {
let attribute = non_empty(hash_attribute).cloned().unwrap_or(String::from("id"));
if let Some(value) = user_attributes.find_value(&attribute).filter(truthy) {
return Some((attribute, value));
}
if fallback_allowed {
if let Some(fallback) = non_empty(fallback_attribute) {
if let Some(value) = user_attributes.find_value(fallback).filter(truthy) {
return Some((fallback.clone(), value));
}
}
}
None
}