Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
z4kn4fein committed Dec 2, 2024
1 parent 751fea8 commit 3cdcf73
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 77 deletions.
12 changes: 6 additions & 6 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ impl Options {
self.offline
}

pub(crate) fn base_url(&self) -> &Option<String> {
&self.base_url
pub(crate) fn base_url(&self) -> Option<&String> {
self.base_url.as_ref()
}

pub(crate) fn data_governance(&self) -> &DataGovernance {
Expand All @@ -50,12 +50,12 @@ impl Options {
&self.polling_mode
}

pub(crate) fn overrides(&self) -> &Option<FlagOverrides> {
&self.overrides
pub(crate) fn overrides(&self) -> Option<&FlagOverrides> {
self.overrides.as_ref()
}

pub(crate) fn default_user(&self) -> &Option<User> {
&self.default_user
pub(crate) fn default_user(&self) -> Option<&User> {
self.default_user.as_ref()
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Client {
Ok(service) => Ok(Self {
options: Arc::clone(&opts),
service,
default_user: Arc::new(Mutex::new(opts.default_user().clone())),
default_user: Arc::new(Mutex::new(opts.default_user().cloned())),
}),
Err(err) => Err(err),
}
Expand Down Expand Up @@ -188,8 +188,8 @@ impl Client {
match eval_flag(
&result.config().settings,
key,
&eval_user,
&Some(default.clone().into()),
eval_user.as_ref(),
Some(&default.clone().into()),
) {
Ok(eval_result) => {
if let Some(val) = T::from_value(&eval_result.value) {
Expand Down Expand Up @@ -240,7 +240,7 @@ impl Client {
if eval_user.is_none() {
eval_user = self.read_def_user();
}
match eval_flag(&result.config().settings, key, &eval_user, &None) {
match eval_flag(&result.config().settings, key, eval_user.as_ref(), None) {
Ok(eval_result) => EvaluationDetails {
value: Some(eval_result.value),
key: key.to_owned(),
Expand Down Expand Up @@ -317,7 +317,7 @@ impl Client {
let mut result = Vec::<EvaluationDetails<Option<Value>>>::with_capacity(settings.len());
for k in settings.keys() {
let usr_clone = eval_user.clone();
let details = match eval_flag(settings, k, &usr_clone, &None) {
let details = match eval_flag(settings, k, usr_clone.as_ref(), None) {
Ok(eval_result) => EvaluationDetails {
value: Some(eval_result.value),
key: k.to_owned(),
Expand Down Expand Up @@ -520,8 +520,8 @@ impl Client {
fn eval_flag(
settings: &HashMap<String, Setting>,
key: &str,
user: &Option<User>,
default: &Option<Value>,
user: Option<&User>,
default: Option<&Value>,
) -> Result<EvalResult, ClientError> {
if settings.is_empty() {
return Err(ClientError::new(ErrorKind::ConfigJsonNotAvailable, format!("Config JSON is not present when evaluating setting '{key}'. Returning the `defaultValue` parameter that you specified in your application: '{}'.", default.to_str())));
Expand Down
59 changes: 32 additions & 27 deletions src/eval/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ impl Display for ConditionResult {
pub fn eval(
setting: &Setting,
key: &str,
user: &Option<User>,
user: Option<&User>,
settings: &HashMap<String, Setting>,
default: &Option<Value>,
default: Option<&Value>,
) -> Result<EvalResult, String> {
let mut eval_log = EvalLogBuilder::default();
let mut cycle_tracker = Vec::<String>::default();
Expand Down Expand Up @@ -143,7 +143,7 @@ pub fn eval(
fn eval_setting(
setting: &Setting,
key: &str,
user: &Option<User>,
user: Option<&User>,
settings: &HashMap<String, Setting>,
log: &mut EvalLogBuilder,
cycle_tracker: &mut Vec<String>,
Expand All @@ -159,10 +159,10 @@ fn eval_setting(
if let Some(conditions) = rule.conditions.as_ref() {
let result = eval_conditions(
conditions,
&rule.served_value,
rule.served_value.as_ref(),
key,
user,
&setting.salt,
setting.salt.as_ref(),
key,
log,
settings,
Expand All @@ -177,7 +177,7 @@ fn eval_setting(
return produce_result(
&served_val.value,
&setting.setting_type,
&served_val.variation_id,
served_val.variation_id.as_ref(),
Some(rule.clone()),
None,
);
Expand All @@ -192,7 +192,7 @@ fn eval_setting(
percentage_opts,
u,
key,
&setting.percentage_attribute,
setting.percentage_attribute.as_ref(),
log,
);
match percentage_result {
Expand All @@ -203,7 +203,7 @@ fn eval_setting(
return produce_result(
&opt.served_value,
&setting.setting_type,
&opt.variation_id,
opt.variation_id.as_ref(),
Some(rule.clone()),
Some(opt.clone()),
);
Expand Down Expand Up @@ -263,14 +263,19 @@ fn eval_setting(

if let Some(percentage_opts) = setting.percentage_options.as_ref() {
if let Some(u) = user {
let percentage_result =
eval_percentage(percentage_opts, u, key, &setting.percentage_attribute, log);
let percentage_result = eval_percentage(
percentage_opts,
u,
key,
setting.percentage_attribute.as_ref(),
log,
);
match percentage_result {
PercentageResult::Success(opt) => {
return produce_result(
&opt.served_value,
&setting.setting_type,
&opt.variation_id,
opt.variation_id.as_ref(),
None,
Some(opt.clone()),
);
Expand All @@ -294,7 +299,7 @@ fn eval_setting(
produce_result(
&setting.value,
&setting.setting_type,
&setting.variation_id,
setting.variation_id.as_ref(),
None,
None,
)
Expand All @@ -303,7 +308,7 @@ fn eval_setting(
fn produce_result(
sv: &SettingValue,
setting_type: &SettingType,
variation: &Option<String>,
variation: Option<&String>,
rule: Option<Arc<TargetingRule>>,
option: Option<Arc<PercentageOption>>,
) -> Result<EvalResult, String> {
Expand All @@ -312,7 +317,7 @@ fn produce_result(
value,
rule,
option,
variation_id: variation.clone(),
variation_id: Some(variation.unwrap_or(&String::default()).to_owned()),
setting_type: setting_type.clone(),
});
}
Expand All @@ -323,7 +328,7 @@ fn eval_percentage(
opts: &[Arc<PercentageOption>],
user: &User,
key: &str,
percentage_attr: &Option<String>,
percentage_attr: Option<&String>,
log: &mut EvalLogBuilder,
) -> PercentageResult {
let attr = if let Some(percentage_attr) = percentage_attr {
Expand Down Expand Up @@ -379,10 +384,10 @@ fn eval_percentage(

fn eval_conditions(
conditions: &[Condition],
rule_srv_value: &Option<ServedValue>,
rule_srv_value: Option<&ServedValue>,
key: &str,
user: &Option<User>,
salt: &Option<String>,
user: Option<&User>,
salt: Option<&String>,
ctx_salt: &str,
log: &mut EvalLogBuilder,
settings: &HashMap<String, Setting>,
Expand Down Expand Up @@ -468,7 +473,7 @@ fn eval_conditions(
fn eval_prerequisite_cond(
cond: &PrerequisiteFlagCondition,
key: &str,
user: &Option<User>,
user: Option<&User>,
log: &mut EvalLogBuilder,
settings: &HashMap<String, Setting>,
cycle_tracker: &mut Vec<String>,
Expand Down Expand Up @@ -538,7 +543,7 @@ fn eval_segment_cond(
cond: &SegmentCondition,
key: &str,
user: &User,
salt: &Option<String>,
salt: Option<&String>,
log: &mut EvalLogBuilder,
) -> ConditionResult {
let Some(segment) = cond.segment.as_ref() else {
Expand Down Expand Up @@ -615,13 +620,13 @@ fn eval_user_cond(
cond: &UserCondition,
key: &str,
user: &User,
salt: &Option<String>,
salt: Option<&String>,
ctx_salt: &str,
) -> ConditionResult {
let Some(user_attr) = user.get(&cond.comp_attr) else {
return AttrMissing(cond.comp_attr.clone(), format!("{cond}"));
};
return match cond.comparator {
match cond.comparator {
Eq | NotEq | EqHashed | NotEqHashed => {
let Some(comp_val) = cond.string_val.as_ref() else {
return CompValInvalid(None);
Expand Down Expand Up @@ -742,14 +747,14 @@ fn eval_user_cond(
};
eval_array_contains(comp_val, &user_val, &cond.comparator, salt, ctx_salt)
}
};
}
}

fn eval_text_eq(
comp_val: &str,
user_val: String,
comp: &UserComparator,
salt: &Option<String>,
salt: Option<&String>,
ctx_salt: &str,
) -> ConditionResult {
let needs_true = if comp.is_sensitive() {
Expand All @@ -771,7 +776,7 @@ fn eval_one_of(
comp_val: &[String],
user_val: String,
comp: &UserComparator,
salt: &Option<String>,
salt: Option<&String>,
ctx_salt: &str,
) -> ConditionResult {
let needs_true = if comp.is_sensitive() {
Expand All @@ -798,7 +803,7 @@ fn eval_starts_ends_with(
comp_val: &[String],
user_val: &str,
comp: &UserComparator,
salt: &Option<String>,
salt: Option<&String>,
ctx_salt: &str,
) -> ConditionResult {
let needs_true = if comp.is_starts_with() {
Expand Down Expand Up @@ -937,7 +942,7 @@ fn eval_array_contains(
comp_val: &[String],
user_val: &[String],
comp: &UserComparator,
salt: &Option<String>,
salt: Option<&String>,
ctx_salt: &str,
) -> ConditionResult {
let needs_true = if comp.is_sensitive() {
Expand Down
2 changes: 1 addition & 1 deletion src/eval/log_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl EvalLogBuilder {
&mut self,
new_line: bool,
result: &ConditionResult,
rule_srv_value: &Option<ServedValue>,
rule_srv_value: Option<&ServedValue>,
) -> &mut Self {
let builder = self.inc_indent();
if new_line {
Expand Down
Loading

0 comments on commit 3cdcf73

Please sign in to comment.