Refactor format_keywords function
This commit is contained in:
parent
fb8d23a22a
commit
a352c88b8f
|
|
@ -126,18 +126,14 @@ impl Query {
|
||||||
/// ## WARNING
|
/// ## WARNING
|
||||||
/// Clones `self.keywords`
|
/// Clones `self.keywords`
|
||||||
fn format_keywords(&self) -> String {
|
fn format_keywords(&self) -> String {
|
||||||
if self.keywords.is_empty() {
|
let mut keywords = self.keywords.clone();
|
||||||
return String::new();
|
match keywords.pop() {
|
||||||
|
None => String::new(),
|
||||||
|
Some(last) => {
|
||||||
|
let head = keywords.join("', '");
|
||||||
|
|
||||||
|
format!("'{}', and '{}'", head, last)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = self
|
|
||||||
.keywords
|
|
||||||
.iter()
|
|
||||||
.take(self.keywords.len() - 1)
|
|
||||||
.map(|s| s.to_string())
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
.join("', '");
|
|
||||||
|
|
||||||
format!("'{}', and '{}'", result, self.keywords.last().unwrap())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue