Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
neilkakkar committed May 30, 2024
1 parent cdcac30 commit 77a0c7e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions feature-flags/src/property_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn match_property(
// TODO: Check if `to_string()` coerces all types to string correctly.
return value
.as_array()
.unwrap()
.expect("expected array value")
.iter()
.map(|v| v.to_string().to_lowercase())
.collect::<Vec<String>>()
Expand Down Expand Up @@ -180,14 +180,17 @@ fn is_truthy_or_falsy_property_value(value: &Value) -> bool {
}

if value.is_string() {
let parsed_value = value.as_str().unwrap().to_lowercase();
let parsed_value = value
.as_str()
.expect("expected string value")
.to_lowercase();
return parsed_value == "true" || parsed_value == "false";
}

if value.is_array() {
return value
.as_array()
.unwrap()
.expect("expected array value")
.iter()
.all(|v| is_truthy_or_falsy_property_value(v));
}
Expand All @@ -197,18 +200,21 @@ fn is_truthy_or_falsy_property_value(value: &Value) -> bool {

fn is_truthy_property_value(value: &Value) -> bool {
if value.is_boolean() {
return value.as_bool().unwrap();
return value.as_bool().expect("expected boolean value");
}

if value.is_string() {
let parsed_value = value.as_str().unwrap().to_lowercase();
let parsed_value = value
.as_str()
.expect("expected string value")
.to_lowercase();
return parsed_value == "true";
}

if value.is_array() {
return value
.as_array()
.unwrap()
.expect("expected array value")
.iter()
.all(|v| is_truthy_property_value(v));
}
Expand Down

0 comments on commit 77a0c7e

Please sign in to comment.