summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClementTsang <cjhtsang@uwaterloo.ca>2020-05-21 21:46:21 -0400
committerClementTsang <cjhtsang@uwaterloo.ca>2020-05-21 21:46:21 -0400
commitc7edad91ed82ea24ed031c13430e3a531e5d0284 (patch)
treedbee6e69ecb34f6d489106c99f957b32dc64d926
parentb33ea11af2d44a49558fcbf48ac7837307ef4143 (diff)
refactor: fix clippy error
-rw-r--r--src/app/query.rs382
1 files changed, 188 insertions, 194 deletions
diff --git a/src/app/query.rs b/src/app/query.rs
index 0d66c207..6a57975c 100644
--- a/src/app/query.rs
+++ b/src/app/query.rs
@@ -163,248 +163,242 @@ impl ProcessQuery for ProcWidgetState {
compare_prefix: None,
});
}
- } else {
- if queue_top == "(" {
- if query.is_empty() {
- return Err(QueryError("Missing closing parentheses".into()));
- }
+ } else if queue_top == "(" {
+ if query.is_empty() {
+ return Err(QueryError("Missing closing parentheses".into()));
+ }
- let mut list_of_ors = VecDeque::new();
+ let mut list_of_ors = VecDeque::new();
- while let Some(in_paren_query_top) = query.front() {
- if in_paren_query_top != ")" {
- list_of_ors.push_back(process_or(query)?);
- } else {
- break;
- }
+ while let Some(in_paren_query_top) = query.front() {
+ if in_paren_query_top != ")" {
+ list_of_ors.push_back(process_or(query)?);
+ } else {
+ break;
}
+ }
- // Ensure not empty
- if list_of_ors.is_empty() {
- return Err(QueryError("No values within parentheses group".into()));
- }
+ // Ensure not empty
+ if list_of_ors.is_empty() {
+ return Err(QueryError("No values within parentheses group".into()));
+ }
- // Now convert this back to a OR...
- let mut returned_or = Or {
+ // Now convert this back to a OR...
+ let mut returned_or = Or {
+ lhs: And {
+ lhs: Prefix {
+ or: Some(Box::new(list_of_ors.pop_front().unwrap())),
+ compare_prefix: None,
+ regex_prefix: None,
+ },
+ rhs: None,
+ },
+ rhs: None,
+ };
+ list_of_ors.into_iter().for_each(|rhs| {
+ returned_or = Or {
lhs: And {
lhs: Prefix {
- or: Some(Box::new(list_of_ors.pop_front().unwrap())),
+ or: Some(Box::new(returned_or.clone())),
compare_prefix: None,
regex_prefix: None,
},
- rhs: None,
+ rhs: Some(Box::new(Prefix {
+ or: Some(Box::new(rhs)),
+ compare_prefix: None,
+ regex_prefix: None,
+ })),
},
rhs: None,
};
- list_of_ors.into_iter().for_each(|rhs| {
- returned_or = Or {
- lhs: And {
- lhs: Prefix {
- or: Some(Box::new(returned_or.clone())),
- compare_prefix: None,
- regex_prefix: None,
- },
- rhs: Some(Box::new(Prefix {
- or: Some(Box::new(rhs)),
- compare_prefix: None,
- regex_prefix: None,
- })),
- },
- rhs: None,
- };
- });
+ });
- if let Some(close_paren) = query.pop_front() {
- if close_paren == ")" {
- return Ok(Prefix {
- or: Some(Box::new(returned_or)),
- regex_prefix: None,
- compare_prefix: None,
- });
- } else {
- return Err(QueryError("Missing closing parentheses".into()));
- }
+ if let Some(close_paren) = query.pop_front() {
+ if close_paren == ")" {
+ return Ok(Prefix {
+ or: Some(Box::new(returned_or)),
+ regex_prefix: None,
+ compare_prefix: None,
+ });
} else {
return Err(QueryError("Missing closing parentheses".into()));
}
- } else if queue_top == ")" {
- return Err(QueryError("Missing opening parentheses".into()));
- } else if queue_top == "\"" {
- // Similar to parentheses, trap and check for missing closing quotes. Note, however, that we
- // will DIRECTLY call another process_prefix call...
-
- let prefix = process_prefix(query, true)?;
- if let Some(close_paren) = query.pop_front() {
- if close_paren == "\"" {
- return Ok(prefix);
- } else {
- return Err(QueryError("Missing closing quotation".into()));
- }
+ } else {
+ return Err(QueryError("Missing closing parentheses".into()));
+ }
+ } else if queue_top == ")" {
+ return Err(QueryError("Missing opening parentheses".into()));
+ } else if queue_top == "\"" {
+ // Similar to parentheses, trap and check for missing closing quotes. Note, however, that we
+ // will DIRECTLY call another process_prefix call...
+
+ let prefix = process_prefix(query, true)?;
+ if let Some(close_paren) = query.pop_front() {
+ if close_paren == "\"" {
+ return Ok(prefix);
} else {
return Err(QueryError("Missing closing quotation".into()));
}
} else {
- // Get prefix type...
- let prefix_type = queue_top.parse::<PrefixType>()?;
- let content = if let PrefixType::Name = prefix_type {
- Some(queue_top)
- } else {
- query.pop_front()
- };
+ return Err(QueryError("Missing closing quotation".into()));
+ }
+ } else {
+ // Get prefix type...
+ let prefix_type = queue_top.parse::<PrefixType>()?;
+ let content = if let PrefixType::Name = prefix_type {
+ Some(queue_top)
+ } else {
+ query.pop_front()
+ };
- if let Some(content) = content {
- match &prefix_type {
- PrefixType::Name => {
- return Ok(Prefix {
- or: None,
- regex_prefix: Some((
- prefix_type,
- StringQuery::Value(content),
- )),
- compare_prefix: None,
- })
- }
- PrefixType::Pid => {
- // We have to check if someone put an "="...
- if content == "=" {
- // Check next string if possible
- if let Some(queue_next) = query.pop_front() {
- return Ok(Prefix {
- or: None,
- regex_prefix: Some((
- prefix_type,
- StringQuery::Value(queue_next),
- )),
- compare_prefix: None,
- });
- }
- } else {
+ if let Some(content) = content {
+ match &prefix_type {
+ PrefixType::Name => {
+ return Ok(Prefix {
+ or: None,
+ regex_prefix: Some((prefix_type, StringQuery::Value(content))),
+ compare_prefix: None,
+ })
+ }
+ PrefixType::Pid => {
+ // We have to check if someone put an "="...
+ if content == "=" {
+ // Check next string if possible
+ if let Some(queue_next) = query.pop_front() {
return Ok(Prefix {
or: None,
regex_prefix: Some((
prefix_type,
- StringQuery::Value(content),
+ StringQuery::Value(queue_next),
)),
compare_prefix: None,
});
}
+ } else {
+ return Ok(Prefix {
+ or: None,
+ regex_prefix: Some((
+ prefix_type,
+ StringQuery::Value(content),
+ )),
+ compare_prefix: None,
+ });
}
- _ => {
- // Now we gotta parse the content... yay.
+ }
+ _ => {
+ // Now we gotta parse the content... yay.
- let mut condition: Option<QueryComparison> = None;
- let mut value: Option<f64> = None;
+ let mut condition: Option<QueryComparison> = None;
+ let mut value: Option<f64> = None;
- if content == "=" {
- condition = Some(QueryComparison::Equal);
- if let Some(queue_next) = query.pop_front() {
- value = queue_next.parse::<f64>().ok();
- } else {
- return Err(QueryError("Missing value".into()));
- }
- } else if content == ">" || content == "<" {
- // We also have to check if the next string is an "="...
- if let Some(queue_next) = query.pop_front() {
- if queue_next == "=" {
- condition = Some(if content == ">" {
- QueryComparison::GreaterOrEqual
- } else {
- QueryComparison::LessOrEqual
- });
- if let Some(queue_next_next) = query.pop_front() {
- value = queue_next_next.parse::<f64>().ok();
- } else {
- return Err(QueryError("Missing value".into()));
- }
+ if content == "=" {
+ condition = Some(QueryComparison::Equal);
+ if let Some(queue_next) = query.pop_front() {
+ value = queue_next.parse::<f64>().ok();
+ } else {
+ return Err(QueryError("Missing value".into()));
+ }
+ } else if content == ">" || content == "<" {
+ // We also have to check if the next string is an "="...
+ if let Some(queue_next) = query.pop_front() {
+ if queue_next == "=" {
+ condition = Some(if content == ">" {
+ QueryComparison::GreaterOrEqual
+ } else {
+ QueryComparison::LessOrEqual
+ });
+ if let Some(queue_next_next) = query.pop_front() {
+ value = queue_next_next.parse::<f64>().ok();
} else {
- condition = Some(if content == ">" {
- QueryComparison::Greater
- } else {
- QueryComparison::Less
- });
- value = queue_next.parse::<f64>().ok();
+ return Err(QueryError("Missing value".into()));
}
} else {
- return Err(QueryError("Missing value".into()));
+ condition = Some(if content == ">" {
+ QueryComparison::Greater
+ } else {
+ QueryComparison::Less
+ });
+ value = queue_next.parse::<f64>().ok();
}
+ } else {
+ return Err(QueryError("Missing value".into()));
}
+ }
- if let Some(condition) = condition {
- if let Some(read_value) = value {
- // Now we want to check one last thing - is there a unit?
- // If no unit, assume base.
- // Furthermore, base must be PEEKED at initially, and will
- // require (likely) prefix_type specific checks
- // Lastly, if it *is* a unit, remember to POP!
-
- let mut value = read_value;
-
- match prefix_type {
- PrefixType::Rps
- | PrefixType::Wps
- | PrefixType::TRead
- | PrefixType::TWrite => {
- if let Some(potential_unit) = query.front() {
- match potential_unit.to_lowercase().as_str()
- {
- "tb" => {
- value *= 1_000_000_000_000.0;
- query.pop_front();
- }
- "tib" => {
- value *= 1_099_511_627_776.0;
- query.pop_front();
- }
- "gb" => {
- value *= 1_000_000_000.0;
- query.pop_front();
- }
- "gib" => {
- value *= 1_073_741_824.0;
- query.pop_front();
- }
- "mb" => {
- value *= 1_000_000.0;
- query.pop_front();
- }
- "mib" => {
- value *= 1_048_576.0;
- query.pop_front();
- }
- "kb" => {
- value *= 1000.0;
- query.pop_front();
- }
- "kib" => {
- value *= 1024.0;
- query.pop_front();
- }
- "b" => {
- // Just gotta pop.
- query.pop_front();
- }
- _ => {}
+ if let Some(condition) = condition {
+ if let Some(read_value) = value {
+ // Now we want to check one last thing - is there a unit?
+ // If no unit, assume base.
+ // Furthermore, base must be PEEKED at initially, and will
+ // require (likely) prefix_type specific checks
+ // Lastly, if it *is* a unit, remember to POP!
+
+ let mut value = read_value;
+
+ match prefix_type {
+ PrefixType::Rps
+ | PrefixType::Wps
+ | PrefixType::TRead
+ | PrefixType::TWrite => {
+ if let Some(potential_unit) = query.front() {
+ match potential_unit.to_lowercase().as_str() {
+ "tb" => {
+ value *= 1_000_000_000_000.0;
+ query.pop_front();
+ }
+ "tib" => {
+ value *= 1_099_511_627_776.0;
+ query.pop_front();
+ }
+ "gb" => {
+ value *= 1_000_000_000.0;
+ query.pop_front();
+ }
+ "gib" => {
+ value *= 1_073_741_824.0;
+ query.pop_front();
+ }
+ "mb" => {
+ value *= 1_000_000.0;
+ query.pop_front();
+ }
+ "mib" => {
+ value *= 1_048_576.0;
+ query.pop_front();
+ }
+ "kb" => {
+ value *= 1000.0;
+ query.pop_front();
+ }
+ "kib" => {
+ value *= 1024.0;
+ query.pop_front();
}
+ "b" => {
+ // Just gotta pop.
+ query.pop_front();
+ }
+ _ => {}
}
}
- _ => {}
}
-
- return Ok(Prefix {
- or: None,
- regex_prefix: None,
- compare_prefix: Some((
- prefix_type,
- NumericalQuery { condition, value },
- )),
- });
+ _ => {}
}
+
+ return Ok(Prefix {
+ or: None,
+ regex_prefix: None,
+ compare_prefix: Some((
+ prefix_type,
+ NumericalQuery { condition, value },
+ )),
+ });
}
}
}
- } else {
- return Err(QueryError("Missing argument for search prefix".into()));
}
+ } else {
+ return Err(QueryError("Missing argument for search prefix".into()));
}
}
} else if inside_quotation {