From: Nicolas Luck Date: Mon, 17 Jul 2023 19:35:00 +0000 (+0200) Subject: fmt machine/parsed_results.rs X-Git-Tag: remove^2~62 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=e7f1e32ee300d510b78a2cbc51e156f6072d8470;p=scryer-prolog.git fmt machine/parsed_results.rs --- diff --git a/src/machine/parsed_results.rs b/src/machine/parsed_results.rs index 984c7439..7938106a 100644 --- a/src/machine/parsed_results.rs +++ b/src/machine/parsed_results.rs @@ -1,8 +1,7 @@ +use crate::atom_table::*; use ordered_float::OrderedFloat; use rug::*; use std::collections::BTreeMap; -use crate::atom_table::*; - #[derive(Debug, Clone, PartialEq, Eq)] pub enum QueryResult { @@ -13,7 +12,7 @@ pub enum QueryResult { #[derive(Debug, Clone, PartialEq, Eq)] pub struct QueryMatch { - pub bindings: BTreeMap + pub bindings: BTreeMap, } #[derive(Debug, Clone, PartialEq, Eq)] @@ -38,18 +37,17 @@ pub enum Value { impl From> for QueryMatch { fn from(bindings: BTreeMap<&str, Value>) -> Self { QueryMatch { - bindings: bindings.into_iter() + bindings: bindings + .into_iter() .map(|(k, v)| (k.to_string(), v)) - .collect::>() + .collect::>(), } } } impl From> for QueryMatch { fn from(bindings: BTreeMap) -> Self { - QueryMatch { - bindings - } + QueryMatch { bindings } } } @@ -65,26 +63,34 @@ impl From> for QueryResult { } // If there is at least one line with true and no matches, return true. - if query_result_lines.iter().any(|l| l == &QueryResultLine::True) + if query_result_lines + .iter() + .any(|l| l == &QueryResultLine::True) && !query_result_lines.iter().any(|l| { - if let &QueryResultLine::Match(_) = l { true } else { false } - }) { + if let &QueryResultLine::Match(_) = l { + true + } else { + false + } + }) + { return QueryResult::True; } // If there is at least one match, return all matches. - let all_matches = query_result_lines.into_iter() + let all_matches = query_result_lines + .into_iter() .filter(|l| { - if let &QueryResultLine::Match(_) = l { true } else { false } - }) - .map(|l| { - match l { - QueryResultLine::Match(m) => { - QueryMatch::from(m) - }, - _ => unreachable!() + if let &QueryResultLine::Match(_) = l { + true + } else { + false } }) + .map(|l| match l { + QueryResultLine::Match(m) => QueryMatch::from(m), + _ => unreachable!(), + }) .collect::>(); if !all_matches.is_empty() { @@ -95,7 +101,6 @@ impl From> for QueryResult { } } - impl TryFrom for QueryResultLine { type Error = (); fn try_from(string: String) -> Result { @@ -103,10 +108,11 @@ impl TryFrom for QueryResultLine { "true" => Ok(QueryResultLine::True), "false" => Ok(QueryResultLine::False), _ => Ok(QueryResultLine::Match( - string.split(",") + string + .split(",") .map(|s| s.trim()) .filter(|s| !s.is_empty()) - .map(|s| -> Result<(String, Value), ()>{ + .map(|s| -> Result<(String, Value), ()> { let mut iter = s.split(" = "); let key = iter.next().unwrap().to_string(); @@ -115,8 +121,8 @@ impl TryFrom for QueryResultLine { Ok((key, Value::try_from(value)?)) }) .filter_map(Result::ok) - .collect::>() - )) + .collect::>(), + )), } } } @@ -128,8 +134,7 @@ impl TryFrom for Value { if trimmed.starts_with("'") && trimmed.ends_with("'") { Ok(Value::String(trimmed[1..trimmed.len() - 1].into())) - } else - if trimmed.starts_with("\"") && trimmed.ends_with("\"") { + } else if trimmed.starts_with("\"") && trimmed.ends_with("\"") { Ok(Value::String(trimmed[1..trimmed.len() - 1].into())) } else if trimmed.starts_with("[") && trimmed.ends_with("]") { let mut iter = trimmed[1..trimmed.len() - 1].split(","); @@ -181,4 +186,4 @@ impl From<&str> for Value { fn from(str: &str) -> Self { Value::String(str.to_string()) } -} \ No newline at end of file +}