chore: update to Rust 2024 edition

This commit is contained in:
mayor
2026-01-04 20:08:16 +01:00
committed by Michel de Graaf
parent f7ebcccdd3
commit 16c8a4bde9
9 changed files with 39 additions and 55 deletions
+1 -1
View File
@@ -5,6 +5,6 @@ resolver = "2"
[workspace.package] [workspace.package]
version = "0.3.0" version = "0.3.0"
authors = ["Michel de Graaf"] authors = ["Michel de Graaf"]
edition = "2021" edition = "2024"
license = "MIT" license = "MIT"
repository = "https://github.com/michel/soulseek-rs" repository = "https://github.com/michel/soulseek-rs"
+2 -3
View File
@@ -156,14 +156,13 @@ impl PeerActor {
let transfer_response = let transfer_response =
MessageFactory::build_transfer_response_message(transfer); MessageFactory::build_transfer_response_message(transfer);
if let Some(ref handle) = self.self_handle { if let Some(ref handle) = self.self_handle
if let Err(e) = && let Err(e) =
handle.send(PeerMessage::SendMessage(transfer_response)) handle.send(PeerMessage::SendMessage(transfer_response))
{ {
error!("[peer:{}] Failed to send TransferResponse message: {}", username, e); error!("[peer:{}] Failed to send TransferResponse message: {}", username, e);
} }
} }
}
PeerMessage::TransferResponse { PeerMessage::TransferResponse {
token, token,
allowed, allowed,
+6 -9
View File
@@ -285,12 +285,11 @@ impl Client {
#[allow(dead_code)] #[allow(dead_code)]
pub fn remove_peer(&self, username: &str) { pub fn remove_peer(&self, username: &str) {
let context = self.context.read().unwrap(); let context = self.context.read().unwrap();
if let Some(ref registry) = context.peer_registry { if let Some(ref registry) = context.peer_registry
if let Some(handle) = registry.remove_peer(username) { && let Some(handle) = registry.remove_peer(username) {
let _ = handle.stop(); let _ = handle.stop();
} }
} }
}
pub fn search( pub fn search(
&self, &self,
@@ -334,12 +333,11 @@ impl Client {
sleep(Duration::from_millis(100)); sleep(Duration::from_millis(100));
// Check if cancelled // Check if cancelled
if let Some(ref flag) = cancel_flag { if let Some(ref flag) = cancel_flag
if flag.load(Ordering::Relaxed) { && flag.load(Ordering::Relaxed) {
info!("Search cancelled by user"); info!("Search cancelled by user");
break; break;
} }
}
// Check if timeout reached // Check if timeout reached
if start.elapsed() >= timeout { if start.elapsed() >= timeout {
@@ -504,13 +502,12 @@ impl Client {
} }
ClientOperation::PeerDisconnected(username, error) => { ClientOperation::PeerDisconnected(username, error) => {
let context = client_context.read().unwrap(); let context = client_context.read().unwrap();
if let Some(ref registry) = context.peer_registry { if let Some(ref registry) = context.peer_registry
if let Some(handle) = && let Some(handle) =
registry.remove_peer(&username) registry.remove_peer(&username)
{ {
let _ = handle.stop(); let _ = handle.stop();
} }
}
if let Some(error) = error { if let Some(error) = error {
warn!( warn!(
"[client] Peer {} disconnected with error: {:?}", "[client] Peer {} disconnected with error: {:?}",
+2 -3
View File
@@ -306,8 +306,8 @@ impl DownloadPeer {
processor.process_data_chunk(data); processor.process_data_chunk(data);
chunk_counter += 1; chunk_counter += 1;
if let Some(ref dl) = download { if let Some(ref dl) = download
if chunk_counter % PROGRESS_UPDATE_CHUNKS == 0 { && chunk_counter % PROGRESS_UPDATE_CHUNKS == 0 {
let elapsed = let elapsed =
last_update_time.elapsed().as_secs_f64(); last_update_time.elapsed().as_secs_f64();
let bytes_since_last_update = let bytes_since_last_update =
@@ -331,7 +331,6 @@ impl DownloadPeer {
last_update_time = Instant::now(); last_update_time = Instant::now();
} }
}
let expected_size = download let expected_size = download
.as_ref() .as_ref()
+2 -3
View File
@@ -167,12 +167,11 @@ pub fn log(level: LogLevel, message: &str) {
buffer.push(formatted_message.clone()); buffer.push(formatted_message.clone());
} }
// But ALSO write to file if configured (file logging bypasses buffering) // But ALSO write to file if configured (file logging bypasses buffering)
if let Ok(mut log_file) = LOG_FILE.lock() { if let Ok(mut log_file) = LOG_FILE.lock()
if let Some(file) = log_file.as_mut() { && let Some(file) = log_file.as_mut() {
let _ = writeln!(file, "{}", formatted_message_plain); let _ = writeln!(file, "{}", formatted_message_plain);
let _ = file.flush(); let _ = file.flush();
} }
}
} else { } else {
// Write to file if configured, otherwise to stderr // Write to file if configured, otherwise to stderr
if let Ok(mut log_file) = LOG_FILE.lock() { if let Ok(mut log_file) = LOG_FILE.lock() {
+4 -2
View File
@@ -27,11 +27,13 @@ fn main() -> Result<()> {
3 => "DEBUG", 3 => "DEBUG",
_ => "TRACE", _ => "TRACE",
}; };
env::set_var("LOG_LEVEL", log_level); // SAFETY: Called before any threads are spawned
unsafe { env::set_var("LOG_LEVEL", log_level) };
// Set LOG_FILE env var if provided via CLI // Set LOG_FILE env var if provided via CLI
if let Some(log_file) = &cli.log_file { if let Some(log_file) = &cli.log_file {
env::set_var("LOG_FILE", log_file.to_string_lossy().to_string()); // SAFETY: Called before any threads are spawned
unsafe { env::set_var("LOG_FILE", log_file.to_string_lossy().to_string()) };
} }
let username = cli.username let username = cli.username
+10 -16
View File
@@ -113,12 +113,11 @@ impl FileSelector {
Duration::from_millis(100) Duration::from_millis(100)
}; };
if poll(timeout)? { if poll(timeout)?
if let Event::Key(key) = event::read()? { && let Event::Key(key) = event::read()? {
self.handle_key(key); self.handle_key(key);
} }
} }
}
Ok((terminal, self.selected_indices.iter().copied().collect())) Ok((terminal, self.selected_indices.iter().copied().collect()))
} }
@@ -157,8 +156,8 @@ impl FileSelector {
} }
fn toggle_selection(&mut self) { fn toggle_selection(&mut self) {
if let Some(filtered_idx) = self.state.selected() { if let Some(filtered_idx) = self.state.selected()
if let Some(&original_idx) = self.filtered_indices.get(filtered_idx) && let Some(&original_idx) = self.filtered_indices.get(filtered_idx)
{ {
if self.selected_indices.contains(&original_idx) { if self.selected_indices.contains(&original_idx) {
self.selected_indices.remove(&original_idx); self.selected_indices.remove(&original_idx);
@@ -167,7 +166,6 @@ impl FileSelector {
} }
} }
} }
}
fn handle_key(&mut self, key: KeyEvent) { fn handle_key(&mut self, key: KeyEvent) {
if key.kind != KeyEventKind::Press { if key.kind != KeyEventKind::Press {
@@ -194,15 +192,13 @@ impl FileSelector {
} }
KeyCode::Enter => { KeyCode::Enter => {
// If nothing selected, select the current item under cursor // If nothing selected, select the current item under cursor
if self.selected_indices.is_empty() { if self.selected_indices.is_empty()
if let Some(filtered_idx) = self.state.selected() { && let Some(filtered_idx) = self.state.selected()
if let Some(&original_idx) = && let Some(&original_idx) =
self.filtered_indices.get(filtered_idx) self.filtered_indices.get(filtered_idx)
{ {
self.selected_indices.insert(original_idx); self.selected_indices.insert(original_idx);
} }
}
}
self.should_exit = true; self.should_exit = true;
} }
KeyCode::Up | KeyCode::Down => { KeyCode::Up | KeyCode::Down => {
@@ -238,15 +234,13 @@ impl FileSelector {
} }
KeyCode::Enter => { KeyCode::Enter => {
// If nothing selected, select the current item under cursor // If nothing selected, select the current item under cursor
if self.selected_indices.is_empty() { if self.selected_indices.is_empty()
if let Some(filtered_idx) = self.state.selected() { && let Some(filtered_idx) = self.state.selected()
if let Some(&original_idx) = && let Some(&original_idx) =
self.filtered_indices.get(filtered_idx) self.filtered_indices.get(filtered_idx)
{ {
self.selected_indices.insert(original_idx); self.selected_indices.insert(original_idx);
} }
}
}
self.should_exit = true; self.should_exit = true;
} }
KeyCode::Esc | KeyCode::Char('q') => { KeyCode::Esc | KeyCode::Char('q') => {
+4 -6
View File
@@ -81,8 +81,8 @@ impl MultiDownloadProgress {
// Poll all receivers for status updates // Poll all receivers for status updates
let mut need_start_next = false; let mut need_start_next = false;
for download_entry in &mut self.downloads { for download_entry in &mut self.downloads {
if let Some(receiver) = &download_entry.receiver { if let Some(receiver) = &download_entry.receiver
if let Ok(status) = receiver.try_recv() { && let Ok(status) = receiver.try_recv() {
let was_active = !download_entry.download.is_finished(); let was_active = !download_entry.download.is_finished();
download_entry.download.status = status; download_entry.download.status = status;
let is_finished = download_entry.download.is_finished(); let is_finished = download_entry.download.is_finished();
@@ -95,7 +95,6 @@ impl MultiDownloadProgress {
} }
} }
} }
}
// Start next batch after iteration completes // Start next batch after iteration completes
if need_start_next { if need_start_next {
@@ -103,11 +102,10 @@ impl MultiDownloadProgress {
} }
// Handle keyboard input // Handle keyboard input
if poll(Duration::from_millis(100))? { if poll(Duration::from_millis(100))?
if let Event::Key(key) = event::read()? { && let Event::Key(key) = event::read()? {
self.handle_key(key); self.handle_key(key);
} }
}
// Exit when user cancels or all downloads finished // Exit when user cancels or all downloads finished
if self.should_exit || self.all_finished() { if self.should_exit || self.all_finished() {
+8 -12
View File
@@ -519,8 +519,8 @@ impl MainTui {
let (col, row) = (mouse.column, mouse.row); let (col, row) = (mouse.column, mouse.row);
// Check if click is within searches pane // Check if click is within searches pane
if let Some(area) = self.state.searches_pane_area { if let Some(area) = self.state.searches_pane_area
if col >= area.x && col >= area.x
&& col < area.x + area.width && col < area.x + area.width
&& row >= area.y && row >= area.y
&& row < area.y + area.height && row < area.y + area.height
@@ -528,11 +528,10 @@ impl MainTui {
self.state.focused_pane = FocusedPane::Searches; self.state.focused_pane = FocusedPane::Searches;
return Ok(()); return Ok(());
} }
}
// Check if click is within results pane // Check if click is within results pane
if let Some(area) = self.state.results_pane_area { if let Some(area) = self.state.results_pane_area
if col >= area.x && col >= area.x
&& col < area.x + area.width && col < area.x + area.width
&& row >= area.y && row >= area.y
&& row < area.y + area.height && row < area.y + area.height
@@ -540,11 +539,10 @@ impl MainTui {
self.state.focused_pane = FocusedPane::Results; self.state.focused_pane = FocusedPane::Results;
return Ok(()); return Ok(());
} }
}
// Check if click is within downloads pane // Check if click is within downloads pane
if let Some(area) = self.state.downloads_pane_area { if let Some(area) = self.state.downloads_pane_area
if col >= area.x && col >= area.x
&& col < area.x + area.width && col < area.x + area.width
&& row >= area.y && row >= area.y
&& row < area.y + area.height && row < area.y + area.height
@@ -553,7 +551,6 @@ impl MainTui {
return Ok(()); return Ok(());
} }
} }
}
Ok(()) Ok(())
} }
@@ -749,8 +746,8 @@ impl MainTui {
} }
// Update selected search if this is the active one // Update selected search if this is the active one
if let Some(selected_idx) = selected_search_index { if let Some(selected_idx) = selected_search_index
if selected_idx == idx { && selected_idx == idx {
self.state.results_items = search.results.clone(); self.state.results_items = search.results.clone();
self.state.results_filtered_items = self.state.results_filtered_items =
search.results.clone(); search.results.clone();
@@ -758,7 +755,6 @@ impl MainTui {
(0..search.results.len()).collect(); (0..search.results.len()).collect();
} }
} }
}
// Mark as completed after timeout // Mark as completed after timeout
if search.status == SearchStatus::Active if search.status == SearchStatus::Active