Skip to content

Commit c53dd4e

Browse files
committed
clippy lints
1 parent 9fca42b commit c53dd4e

File tree

7 files changed

+60
-65
lines changed

7 files changed

+60
-65
lines changed

crates/sample-async/src/bin/async-actor.rs

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -148,52 +148,48 @@ async fn main() -> Result<(), Box<dyn Error>> {
148148
.await?;
149149
},
150150
["message", n] =>
151-
if let Ok(idx) = n.parse::<usize>() {
152-
if let Some((tx, _)) = controls.get(idx) {
153-
println!("Enter message for Actor {}:", idx);
154-
let mut msg = String::new();
155-
std::io::stdin().read_line(&mut msg)
156-
.unwrap();
157-
tx.send(ActorMessage::SetMessage(msg.trim().to_string()))
158-
.await
159-
.unwrap_or_else(|e| eprintln!("Failed to send message: {}", e));
160-
}
151+
if let Ok(idx) = n.parse::<usize>()
152+
&& let Some((tx, _)) = controls.get(idx)
153+
{
154+
println!("Enter message for Actor {}:", idx);
155+
let mut msg = String::new();
156+
std::io::stdin().read_line(&mut msg)
157+
.unwrap();
158+
tx.send(ActorMessage::SetMessage(msg.trim().to_string()))
159+
.await
160+
.unwrap_or_else(|e| eprintln!("Failed to send message: {}", e));
161161
},
162162
["activate", n] =>
163-
if let Ok(idx) = n.parse::<usize>() {
164-
if let Some((tx, _)) = controls.get(idx) {
165-
tx.send(ActorMessage::SetActive)
166-
.await
167-
.unwrap_or_else(|e| eprintln!("Failed to activate actor {}: {}", idx, e));
168-
}
163+
if let Ok(idx) = n.parse::<usize>()
164+
&& let Some((tx, _)) = controls.get(idx)
165+
{
166+
tx.send(ActorMessage::SetActive)
167+
.await
168+
.unwrap_or_else(|e| eprintln!("Failed to activate actor {}: {}", idx, e));
169169
},
170170
["deactivate", n] =>
171-
if let Ok(idx) = n.parse::<usize>() {
172-
if let Some((tx, _)) = controls.get(idx) {
173-
tx.send(ActorMessage::SetInactive)
174-
.await
175-
.unwrap_or_else(|e| {
176-
eprintln!("Failed to deactivate actor {}: {}", idx, e)
177-
});
178-
}
171+
if let Ok(idx) = n.parse::<usize>()
172+
&& let Some((tx, _)) = controls.get(idx)
173+
{
174+
tx.send(ActorMessage::SetInactive)
175+
.await
176+
.unwrap_or_else(|e| eprintln!("Failed to deactivate actor {}: {}", idx, e));
179177
},
180178
["toggle", n] =>
181-
if let Ok(idx) = n.parse::<usize>() {
182-
if let Some((tx, _)) = controls.get(idx) {
183-
tx.send(ActorMessage::ToggleActive)
184-
.await
185-
.unwrap_or_else(|e| eprintln!("Failed to toggle actor {}: {}", idx, e));
186-
}
179+
if let Ok(idx) = n.parse::<usize>()
180+
&& let Some((tx, _)) = controls.get(idx)
181+
{
182+
tx.send(ActorMessage::ToggleActive)
183+
.await
184+
.unwrap_or_else(|e| eprintln!("Failed to toggle actor {}: {}", idx, e));
187185
},
188186
["rate", n, ms] =>
189-
if let (Ok(idx), Ok(ms)) = (n.parse::<usize>(), ms.parse::<u64>()) {
190-
if let Some((tx, _)) = controls.get(idx) {
191-
tx.send(ActorMessage::SetPeriod(Duration::from_millis(ms)))
192-
.await
193-
.unwrap_or_else(|e| {
194-
eprintln!("Failed to set rate for actor {}: {}", idx, e)
195-
});
196-
}
187+
if let (Ok(idx), Ok(ms)) = (n.parse::<usize>(), ms.parse::<u64>())
188+
&& let Some((tx, _)) = controls.get(idx)
189+
{
190+
tx.send(ActorMessage::SetPeriod(Duration::from_millis(ms)))
191+
.await
192+
.unwrap_or_else(|e| eprintln!("Failed to set rate for actor {}: {}", idx, e));
197193
},
198194
["report"] =>
199195
for (idx, (tx, _)) in controls.iter().enumerate() {

crates/sample-async/src/main.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ use std::time::Duration;
2727
use reqwest::{Method, Url,
2828
header::{self, HeaderMap}};
2929
use serde::{Deserialize, Serialize};
30-
use tracing::Level as L;
31-
use tracing::event;
30+
use tracing::{Level as L, event};
3231
use utilities::activate_global_default_tracing_subscriber;
3332

3433
// #[cfg(not(target_arch = "wasm32"))]
@@ -55,7 +54,8 @@ async fn main() -> SampleResult<()> {
5554
let base_httpbin = Url::parse(URL_HTTPBIN)?;
5655
let delay_httpbin = base_httpbin.join("/delay/")?;
5756
let json_httpbin = base_httpbin.join("/json")?;
58-
event!(L::DEBUG, ?base_httpbin,
57+
event!(L::DEBUG,
58+
?base_httpbin,
5959
?base_typicode,
6060
?todos_typicode,
6161
?delay_httpbin,
@@ -308,8 +308,10 @@ async fn _fetch_with_retry(client: &reqwest::Client,
308308
tokio::time::sleep(Duration::from_millis(2u64.pow(retries))).await;
309309
},
310310
Err(e) => {
311-
event!(L::ERROR, "Request tried {} times without success. Last error returned: {}",
312-
retries, e);
311+
event!(L::ERROR,
312+
"Request tried {} times without success. Last error returned: {}",
313+
retries,
314+
e);
313315
return Err(e.into());
314316
},
315317
}

crates/sample-egui/src/bin/egui-async-semaphore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use serde::{Deserialize, Serialize};
3333
use serde_json::Value as JsonValue;
3434
use tokio::{sync::Semaphore, task::JoinSet, time::interval};
3535
use tokio_util::{sync::CancellationToken, task::TaskTracker};
36-
use tracing::{event, Level as L, Instrument, debug_span, instrument};
36+
use tracing::{Instrument, Level as L, debug_span, event, instrument};
3737
use utilities::activate_global_default_tracing_subscriber;
3838
// ///////////////////////////////// [ main ] ///////////////////////////////// //
3939
#[tokio::main(flavor = "multi_thread")]

crates/sample-egui/src/bin/egui-filedialog.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@ impl eframe::App for MyApp {
2727

2828
if ui.button("Open file…")
2929
.clicked()
30+
&& let Some(path) = rfd::FileDialog::new().pick_file()
3031
{
31-
if let Some(path) = rfd::FileDialog::new().pick_file()
32-
{
33-
self.picked_path =
34-
Some(path.display().to_string());
35-
}
32+
self.picked_path = Some(path.display().to_string());
3633
}
3734

3835
if let Some(picked_path) = &self.picked_path {

crates/sample-egui/src/bin/egui-table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,5 +340,5 @@ fn long_text(row_index: usize) -> String {
340340
}
341341

342342
fn thick_row(row_index: usize) -> bool {
343-
row_index % 6 == 0
343+
row_index.is_multiple_of(6)
344344
}

crates/sample-egui/src/bin/egui-two-num-calc-thread.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,21 @@ impl eframe::App for TwoNumCalc {
6363
#[expect(unused)]
6464
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
6565
// ............................ [ check for messages ] ............................ //
66-
if let Some(receiver) = &self.receiver {
67-
if receiver.try_recv().is_ok() {
68-
if let (Some(left), Some(right)) = (self.left, self.right) {
69-
self.left = Some(left - 1);
70-
self.right = Some(right + 1);
71-
self.left_text = self.left.unwrap().to_string();
72-
self.right_text = self.right
73-
.unwrap()
74-
.to_string();
75-
// **NOTE**: we need to request repaint if we want UI to update even if we're not otherwise interacting with it.
76-
ctx.request_repaint();
77-
// ctx.request_repaint_after(Duration::from_millis(100)); // if there's no other interaction 100ms seems to result in faster update than just repaint alone...
78-
}
79-
}
66+
if let Some(receiver) = &self.receiver
67+
&& receiver.try_recv().is_ok()
68+
&& let (Some(left), Some(right)) = (self.left, self.right)
69+
{
70+
self.left = Some(left - 1);
71+
self.right = Some(right + 1);
72+
self.left_text = self.left.unwrap().to_string();
73+
self.right_text = self.right
74+
.unwrap()
75+
.to_string();
76+
// **NOTE**: we need to request repaint if we want UI to update even if we're not otherwise interacting with it.
77+
ctx.request_repaint();
78+
// ctx.request_repaint_after(Duration::from_millis(100)); // if there's no other interaction 100ms seems to result in faster update than just repaint alone...
8079
}
80+
8181
// ............................ [ regular rendering ] ............................ //
8282
// -- Menu Bar --
8383
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {

crates/utilities/src/hidden_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use std::{env, ffi::OsStr, num::NonZeroUsize};
5555
use bon::bon;
5656
use dotenvy::dotenv;
5757
use thiserror::Error;
58-
use tracing::{event, Level as L, instrument as instrument_nobonconflict}; // TODO: instrument_nobonconflict temporary to prevent unavoidable compiler warnings from bon
58+
use tracing::{Level as L, event, instrument as instrument_nobonconflict}; // TODO: instrument_nobonconflict temporary to prevent unavoidable compiler warnings from bon
5959
// ///////////////////////////////// [ error ] ///////////////////////////////// //
6060
#[derive(Debug, Error)]
6161
pub enum HiddenValueError {

0 commit comments

Comments
 (0)