chore: migrate to Rust 2024 edition

This commit is contained in:
Vukašin Vojinović 2025-09-03 23:24:38 +02:00 committed by Jeremy Soller
parent 6ed7bdb45f
commit f95869a631
16 changed files with 194 additions and 161 deletions

View file

@ -1,6 +1,16 @@
use cosmic::{
cosmic_theme, font,
Element, cosmic_theme, font,
iced::{
Alignment,
Border,
Color,
ContentFit,
Length,
Point,
Rectangle,
Size,
Subscription,
Vector,
advanced::{
graphics,
text::{self, Paragraph},
@ -17,36 +27,24 @@ use cosmic::{
scrollable::{self, AbsoluteOffset, Viewport},
},
window,
Alignment,
Border,
Color,
ContentFit,
Length,
Point,
Rectangle,
Size,
Subscription,
Vector,
},
iced_core::{mouse::ScrollDelta, widget::tree},
theme,
widget::{
self,
self, DndDestination, DndSource, Id, Space, Widget,
menu::{action::MenuAction, key_bind::KeyBind},
DndDestination, DndSource, Id, Space, Widget,
},
Element,
};
use chrono::{DateTime, Datelike, Timelike, Utc};
use i18n_embed::LanguageLoader;
use icu::datetime::{
options::{components, preferences},
DateTimeFormatter, DateTimeFormatterOptions,
options::{components, preferences},
};
use image::ImageDecoder;
use jxl_oxide::integration::JxlDecoder;
use mime_guess::{mime, Mime};
use mime_guess::{Mime, mime};
use once_cell::sync::Lazy;
use ordermap::OrderMap;
use serde::{Deserialize, Serialize};
@ -62,7 +60,7 @@ use std::{
io::{BufRead, BufReader},
os::unix::fs::MetadataExt,
path::{Path, PathBuf},
sync::{atomic, Arc, LazyLock, Mutex, RwLock},
sync::{Arc, LazyLock, Mutex, RwLock, atomic},
time::{Duration, Instant, SystemTime},
};
use tempfile::NamedTempFile;
@ -73,7 +71,7 @@ use walkdir::WalkDir;
use crate::{
app::{Action, PreviewItem, PreviewKind},
clipboard::{ClipboardCopy, ClipboardKind, ClipboardPaste},
config::{DesktopConfig, IconSizes, TabConfig, ThumbCfg, ICON_SCALE_MAX, ICON_SIZE_GRID},
config::{DesktopConfig, ICON_SCALE_MAX, ICON_SIZE_GRID, IconSizes, TabConfig, ThumbCfg},
dialog::DialogKind,
fl,
localize::{LANGUAGE_SORTER, LOCALE},
@ -4020,11 +4018,7 @@ impl Tab {
fn column_sort(&self) -> Option<Vec<(usize, &Item)>> {
let check_reverse = |ord: Ordering, sort: bool| {
if sort {
ord
} else {
ord.reverse()
}
if sort { ord } else { ord.reverse() }
};
let mut items: Vec<_> = self.items_opt.as_ref()?.iter().enumerate().collect();
let (sort_name, sort_direction, folders_first) = self.sort_options();
@ -4658,29 +4652,31 @@ impl Tab {
pub fn empty_view(&self, has_hidden: bool) -> Element<Message> {
let cosmic_theme::Spacing { space_xxs, .. } = theme::active().cosmic().spacing;
mouse_area::MouseArea::new(widget::column::with_children(vec![widget::container(
widget::column::with_children(match self.mode {
Mode::App | Mode::Dialog(_) => vec![
widget::icon::from_name("folder-symbolic")
.size(64)
.icon()
mouse_area::MouseArea::new(widget::column::with_children(vec![
widget::container(
widget::column::with_children(match self.mode {
Mode::App | Mode::Dialog(_) => vec![
widget::icon::from_name("folder-symbolic")
.size(64)
.icon()
.into(),
widget::text::body(if has_hidden {
fl!("empty-folder-hidden")
} else if matches!(self.location, Location::Search(..)) {
fl!("no-results")
} else {
fl!("empty-folder")
})
.into(),
widget::text::body(if has_hidden {
fl!("empty-folder-hidden")
} else if matches!(self.location, Location::Search(..)) {
fl!("no-results")
} else {
fl!("empty-folder")
})
.into(),
],
Mode::Desktop => Vec::new(),
})
.align_x(Alignment::Center)
.spacing(space_xxs),
)
.center(Length::Fill)
.into()]))
],
Mode::Desktop => Vec::new(),
})
.align_x(Alignment::Center)
.spacing(space_xxs),
)
.center(Length::Fill)
.into(),
]))
.on_press(|_| Message::Click(None))
.into()
}
@ -6109,11 +6105,11 @@ mod tests {
use tempfile::TempDir;
use test_log::test;
use super::{respond_to_scroll_direction, scan_path, Location, Message, Tab};
use super::{Location, Message, Tab, respond_to_scroll_direction, scan_path};
use crate::{
app::test_utils::{
assert_eq_tab_path, empty_fs, eq_path_item, filter_dirs, read_dir_sorted, simple_fs,
tab_click_new, NAME_LEN, NUM_DIRS, NUM_FILES, NUM_HIDDEN, NUM_NESTED,
NAME_LEN, NUM_DIRS, NUM_FILES, NUM_HIDDEN, NUM_NESTED, assert_eq_tab_path, empty_fs,
eq_path_item, filter_dirs, read_dir_sorted, simple_fs, tab_click_new,
},
config::{IconSizes, TabConfig, ThumbCfg},
};
@ -6166,12 +6162,16 @@ mod tests {
);
// All directories (simple_fs only produces one nested layer)
let dirs: Vec<PathBuf> = filter_dirs(path)?
.flat_map(|dir| {
filter_dirs(&dir).map(|nested_dirs| std::iter::once(dir).chain(nested_dirs))
})
.flatten()
.collect();
let dirs: Vec<PathBuf> = {
let top_level = filter_dirs(path)?;
let mut result = Vec::new();
for dir in top_level {
let nested_dirs: Vec<PathBuf> = filter_dirs(&dir)?.collect();
result.push(dir);
result.extend(nested_dirs);
}
result
};
assert!(
dirs.len() == NUM_DIRS + NUM_DIRS * NUM_NESTED,
"Sanity check: Have {} dirs instead of {}",
@ -6210,10 +6210,12 @@ mod tests {
assert_eq!(entries.len(), actual.len());
// Correct files should be scanned
assert!(entries
.into_iter()
.zip(actual.into_iter())
.all(|(path, item)| eq_path_item(&path, &item)));
assert!(
entries
.into_iter()
.zip(actual.into_iter())
.all(|(path, item)| eq_path_item(&path, &item))
);
Ok(())
}
@ -6483,7 +6485,7 @@ mod tests {
#[test]
fn mode_calculations() {
use super::{
get_mode_part, set_mode_part, MODE_SHIFT_GROUP, MODE_SHIFT_OTHER, MODE_SHIFT_USER,
MODE_SHIFT_GROUP, MODE_SHIFT_OTHER, MODE_SHIFT_USER, get_mode_part, set_mode_part,
};
for user in 0..=7 {
for group in 0..=7 {