Skip to content

Commit dfc3cf8

Browse files
fix: apply cargo fmt formatting fixes
Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <[email protected]>
1 parent 250dfa2 commit dfc3cf8

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

src/main.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,37 @@ fn main() {
2626
if options.output_format == OutputFormat::StdOut {
2727
println!("Starting Cloudflare speed test");
2828
}
29-
29+
3030
let client = match build_http_client(&options) {
3131
Ok(client) => client,
3232
Err(e) => {
3333
eprintln!("Error: {}", e);
3434
std::process::exit(1);
3535
}
3636
};
37-
37+
3838
speed_test(client, options);
3939
}
4040

4141
fn build_http_client(options: &SpeedTestCLIOptions) -> Result<reqwest::blocking::Client, String> {
42-
let mut builder = reqwest::blocking::Client::builder()
43-
.timeout(std::time::Duration::from_secs(30));
44-
42+
let mut builder =
43+
reqwest::blocking::Client::builder().timeout(std::time::Duration::from_secs(30));
44+
4545
if let Some(ref ip) = options.ipv4 {
46-
let ip_addr = ip.parse::<IpAddr>().map_err(|e| format!("Invalid IPv4 address '{}': {}", ip, e))?;
46+
let ip_addr = ip
47+
.parse::<IpAddr>()
48+
.map_err(|e| format!("Invalid IPv4 address '{}': {}", ip, e))?;
4749
builder = builder.local_address(ip_addr);
4850
} else if let Some(ref ip) = options.ipv6 {
49-
let ip_addr = ip.parse::<IpAddr>().map_err(|e| format!("Invalid IPv6 address '{}': {}", ip, e))?;
51+
let ip_addr = ip
52+
.parse::<IpAddr>()
53+
.map_err(|e| format!("Invalid IPv6 address '{}': {}", ip, e))?;
5054
builder = builder.local_address(ip_addr);
5155
}
52-
53-
builder.build().map_err(|e| format!("Failed to initialize HTTP client: {}", e))
56+
57+
builder
58+
.build()
59+
.map_err(|e| format!("Failed to initialize HTTP client: {}", e))
5460
}
5561

5662
#[cfg(test)]
@@ -64,7 +70,7 @@ mod tests {
6470
ipv6: None,
6571
..Default::default()
6672
};
67-
73+
6874
let result = build_http_client(&options);
6975
assert!(result.is_err());
7076
let err = result.unwrap_err();
@@ -79,7 +85,7 @@ mod tests {
7985
ipv6: Some("invalid-ipv6".to_string()),
8086
..Default::default()
8187
};
82-
88+
8389
let result = build_http_client(&options);
8490
assert!(result.is_err());
8591
let err = result.unwrap_err();
@@ -94,7 +100,7 @@ mod tests {
94100
ipv6: None,
95101
..Default::default()
96102
};
97-
103+
98104
let result = build_http_client(&options);
99105
assert!(result.is_ok());
100106
}
@@ -106,7 +112,7 @@ mod tests {
106112
ipv6: Some("::1".to_string()),
107113
..Default::default()
108114
};
109-
115+
110116
let result = build_http_client(&options);
111117
assert!(result.is_ok());
112118
}
@@ -118,7 +124,7 @@ mod tests {
118124
ipv6: None,
119125
..Default::default()
120126
};
121-
127+
122128
let result = build_http_client(&options);
123129
assert!(result.is_ok());
124130
}

src/speedtest.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ pub fn test_latency(client: &Client) -> f64 {
201201
return duration; // Return full duration if we can't parse server timing
202202
}
203203
};
204-
204+
205205
match re.captures(header_str) {
206206
Some(captures) => match captures.get(1) {
207207
Some(dur_match) => match dur_match.as_str().parse::<f64>() {
@@ -232,7 +232,7 @@ pub fn test_latency(client: &Client) -> f64 {
232232
return duration;
233233
}
234234
};
235-
235+
236236
let mut req_latency = duration - cf_req_duration;
237237
if req_latency < 0.0 {
238238
log::warn!("Negative latency calculated: {req_latency}ms, using 0.0ms instead");
@@ -294,7 +294,7 @@ pub fn test_upload(client: &Client, payload_size_bytes: usize, output_format: Ou
294294
let url = &format!("{BASE_URL}/{UPLOAD_URL}");
295295
let payload: Vec<u8> = vec![1; payload_size_bytes];
296296
let req_builder = client.post(url).body(payload);
297-
297+
298298
let start = Instant::now();
299299
let response = match req_builder.send() {
300300
Ok(res) => res,
@@ -306,7 +306,7 @@ pub fn test_upload(client: &Client, payload_size_bytes: usize, output_format: Ou
306306
let status_code = response.status();
307307
let duration = start.elapsed();
308308
let mbits = (payload_size_bytes as f64 * 8.0 / 1_000_000.0) / duration.as_secs_f64();
309-
309+
310310
if output_format == OutputFormat::StdOut {
311311
print_current_speed(mbits, duration, status_code, payload_size_bytes);
312312
}
@@ -320,7 +320,7 @@ pub fn test_download(
320320
) -> f64 {
321321
let url = &format!("{BASE_URL}/{DOWNLOAD_URL}{payload_size_bytes}");
322322
let req_builder = client.get(url);
323-
323+
324324
let start = Instant::now();
325325
let response = match req_builder.send() {
326326
Ok(res) => res,
@@ -333,7 +333,7 @@ pub fn test_download(
333333
let _res_bytes = response.bytes();
334334
let duration = start.elapsed();
335335
let mbits = (payload_size_bytes as f64 * 8.0 / 1_000_000.0) / duration.as_secs_f64();
336-
336+
337337
if output_format == OutputFormat::StdOut {
338338
print_current_speed(mbits, duration, status_code, payload_size_bytes);
339339
}

0 commit comments

Comments
 (0)