Skip to content

Commit e376670

Browse files
jplattepoljar
authored andcommitted
refactor(xtask): Fix clippy lints
1 parent 7f08793 commit e376670

2 files changed

Lines changed: 11 additions & 14 deletions

File tree

xtask/src/log/sync.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,9 @@ pub(super) fn run(log_path: path::PathBuf, output_path: path::PathBuf) -> Result
8787
let connection_id =
8888
captures.name("connection_id").expect("Failed to capture `connection_id`").as_str();
8989
let pos = captures.name("pos").map(|pos| pos.as_str());
90-
let timeout = captures
91-
.name("timeout")
92-
.map(|timeout| timeout.as_str().parse::<u64>().ok().map(Duration::from_millis))
93-
.flatten();
90+
let timeout = captures.name("timeout").and_then(|timeout| {
91+
timeout.as_str().parse::<u64>().ok().map(Duration::from_millis)
92+
});
9493
let request_id = captures
9594
.name("request_id")
9695
.expect("Failed to capture `request_id`")
@@ -103,23 +102,22 @@ pub(super) fn run(log_path: path::PathBuf, output_path: path::PathBuf) -> Result
103102
captures.name("request_size").map(|request_size| request_size.as_str());
104103
let response_size =
105104
captures.name("response_size").map(|response_size| response_size.as_str());
106-
let status =
107-
captures.name("status").map(|status| status.as_str().parse().ok()).flatten();
105+
let status = captures.name("status").and_then(|status| status.as_str().parse().ok());
108106

109107
if let Some(smallest_start_at_inner) = smallest_start_at {
110108
if smallest_start_at_inner > date_time {
111-
smallest_start_at = Some(date_time.clone());
109+
smallest_start_at = Some(date_time);
112110
}
113111
} else {
114-
smallest_start_at = Some(date_time.clone());
112+
smallest_start_at = Some(date_time);
115113
}
116114

117115
if let Some(largest_end_at_inner) = largest_end_at {
118116
if largest_end_at_inner < date_time {
119-
largest_end_at = Some(date_time.clone());
117+
largest_end_at = Some(date_time);
120118
}
121119
} else {
122-
largest_end_at = Some(date_time.clone());
120+
largest_end_at = Some(date_time);
123121
}
124122

125123
let spans_for_connection_id = spans.entry(connection_id.to_owned()).or_default();
@@ -170,7 +168,7 @@ pub(super) fn run(log_path: path::PathBuf, output_path: path::PathBuf) -> Result
170168
let end_at = largest_end_at.saturating_sub(smallest_start_at).to_string();
171169
let rows = spans
172170
.iter()
173-
.map(|(connection_id, spans)| {
171+
.flat_map(|(connection_id, spans)| {
174172
spans.iter().map(
175173
|(
176174
request_id,
@@ -189,7 +187,7 @@ pub(super) fn run(log_path: path::PathBuf, output_path: path::PathBuf) -> Result
189187
},
190188
)| {
191189
let uri = Url::parse(uri);
192-
let duration = duration.num_milliseconds().abs() as u64;
190+
let duration = duration.num_milliseconds().unsigned_abs();
193191
let timeout: Option<u64> = timeout.map(|timeout| timeout.as_millis().try_into().expect("Failed to cast a u128 to u64"));
194192

195193
format!(
@@ -265,7 +263,6 @@ pub(super) fn run(log_path: path::PathBuf, output_path: path::PathBuf) -> Result
265263
},
266264
)
267265
})
268-
.flatten()
269266
.collect::<String>();
270267

271268
let output = OUTPUT_TEMPLATE

xtask/src/log/timer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ pub(super) fn run(log_path: path::PathBuf, output_path: path::PathBuf) -> Result
172172

173173
let output = OUTPUT_TEMPLATE.replace("{log_file}", &log_path.to_string_lossy()).replace(
174174
"{longest-duration}",
175-
&timers.get(0).map(|timer| timer.duration.as_nanos()).unwrap_or(0).to_string(),
175+
&timers.first().map(|timer| timer.duration.as_nanos()).unwrap_or(0).to_string(),
176176
);
177177

178178
output_file.write_all(output.as_bytes()).expect("Failed to write the output");

0 commit comments

Comments
 (0)