Skip to content

Commit 9e2ecb5

Browse files
committed
refactor: replace unwrap() with if let Some() in snapshot parsing
So clippy is happy and update test Signed-off-by: Roman Dmytrenko <[email protected]>
1 parent e464a68 commit 9e2ecb5

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

flipt-evaluation/src/lib.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -989,10 +989,11 @@ mod tests {
989989
);
990990

991991
assert!(result_one.is_err());
992-
assert_eq!(
993-
result_one.err().unwrap().to_string(),
994-
"invalid request: error parsing time blah: input contains invalid characters"
995-
);
992+
assert!(result_one
993+
.err()
994+
.unwrap()
995+
.to_string()
996+
.contains("invalid request: error parsing time blah: "));
996997

997998
let result_two = matches_datetime(
998999
&flipt::EvaluationConstraint {
@@ -1005,10 +1006,11 @@ mod tests {
10051006
);
10061007

10071008
assert!(result_two.is_err());
1008-
assert_eq!(
1009-
result_two.err().unwrap().to_string(),
1010-
"invalid request: error parsing time blah: input contains invalid characters"
1011-
);
1009+
assert!(result_two
1010+
.err()
1011+
.unwrap()
1012+
.to_string()
1013+
.contains("invalid request: error parsing time blah: "));
10121014
}
10131015

10141016
#[test]

flipt-evaluation/src/models/snapshot.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ impl Snapshot {
7676
segment_operator: rule.segment_operator,
7777
};
7878

79-
if rule.segments.is_some() {
80-
let rule_segments = rule.segments.unwrap();
81-
79+
if let Some(rule_segments) = rule.segments {
8280
for rule_segment in rule_segments {
8381
let mut eval_constraints: Vec<flipt::EvaluationConstraint> = Vec::new();
8482
for constraint in rule_segment.constraints {
@@ -137,20 +135,17 @@ impl Snapshot {
137135

138136
evaluation_rollout.rank = rollout_idx;
139137

140-
if rollout.threshold.is_some() {
141-
let threshold = rollout.threshold.unwrap();
138+
if let Some(threshold) = rollout.threshold {
142139
evaluation_rollout.threshold = Some(flipt::RolloutThreshold {
143140
percentage: threshold.percentage,
144141
value: threshold.value,
145142
});
146143

147144
evaluation_rollout.rollout_type = flipt::RolloutType::Threshold;
148-
} else if rollout.segment.is_some() {
145+
} else if let Some(segment_rule) = rollout.segment {
149146
let mut evaluation_rollout_segments: HashMap<String, flipt::EvaluationSegment> =
150147
HashMap::new();
151148

152-
let segment_rule = rollout.segment.unwrap();
153-
154149
for segment in segment_rule.segments {
155150
let mut constraints: Vec<flipt::EvaluationConstraint> = Vec::new();
156151
for constraint in segment.constraints {

0 commit comments

Comments
 (0)