Skip to content

Commit 2e01388

Browse files
committed
User itertools::join instead of collecting and joining
1 parent 438ba1c commit 2e01388

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

Cargo.lock

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ edition = "2018"
1010
reqwest = "0.9.17"
1111
futures = "0.1.27"
1212
tokio = "0.1.20"
13-
either = "1.5.2"
13+
itertools = "0.8"

src/main.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#![allow(dead_code)]
22

3+
extern crate itertools;
4+
35
extern crate futures;
46
extern crate reqwest;
57
extern crate tokio;
68

79
use futures::Future;
8-
use reqwest::r#async::Client;
910

11+
use itertools::Itertools;
12+
use reqwest::r#async::Client;
1013
trait InfluxDbQuery {
1114
fn build<'a>(self) -> String;
1215
}
@@ -55,13 +58,11 @@ impl InfluxDbQuery for InfluxDbWrite {
5558
.tags
5659
.into_iter()
5760
.map(|(tag, value)| format!("{tag}={value}", tag = tag, value = value))
58-
.collect::<Vec<String>>()
5961
.join(",");
6062
let fields = self
6163
.fields
6264
.into_iter()
6365
.map(|(field, value)| format!("{field}={value}", field = field, value = value))
64-
.collect::<Vec<String>>()
6566
.join(",");
6667

6768
format!(
@@ -136,9 +137,8 @@ mod tests {
136137

137138
#[test]
138139
fn test_write_builder_single_field() {
139-
let query = InfluxDbQuery::write()
140-
.add_field("water_level", "2");
141-
140+
let query = InfluxDbQuery::write().add_field("water_level", "2");
141+
142142
assert_eq!(query.build(), "measurement, water_level=2 time");
143143
}
144144

@@ -159,8 +159,7 @@ mod tests {
159159
// fixme: quoting / escaping of long strings
160160
#[test]
161161
fn test_write_builder_single_tag() {
162-
let query = InfluxDbQuery::write()
163-
.add_tag("marina_manager", "Smith");
162+
let query = InfluxDbQuery::write().add_tag("marina_manager", "Smith");
164163

165164
assert_eq!(query.build(), "measurement,marina_manager=Smith time");
166165
}
@@ -194,6 +193,9 @@ mod tests {
194193

195194
#[test]
196195
fn test_test() {
197-
InfluxDbQuery::write().add_field("test", "1").add_tag("my_tag", "0.85").build();
196+
InfluxDbQuery::write()
197+
.add_field("test", "1")
198+
.add_tag("my_tag", "0.85")
199+
.build();
198200
}
199201
}

0 commit comments

Comments
 (0)