Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clippy lint #1105

Merged
merged 4 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions crates/rattler_lock/src/parse/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,27 +280,20 @@ fn parse_from_lock<P>(
.iter()
.find(|&idx| {
let conda_package = &conda_packages[*idx];
name.as_ref().map_or(true, |name| {
name.as_ref().is_none_or(|name| {
name == &conda_package.record().name
}) && version.as_ref().map_or(
true,
}) && version.as_ref().is_none_or(
|version| {
version
== &conda_package
.record()
.version
},
) && build.as_ref().map_or(true, |build| {
) && build.as_ref().is_none_or(|build| {
build == &conda_package.record().build
}) && subdir.as_ref().map_or(
true,
|subdir| {
subdir
== &conda_package
.record()
.subdir
},
)
}) && subdir.as_ref().is_none_or(|subdir| {
subdir == &conda_package.record().subdir
})
})
.copied()
};
Expand Down
25 changes: 11 additions & 14 deletions crates/rattler_menuinst/src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,20 +569,17 @@ impl LinuxMenu {
let file_path = temp_dir.path().join(file_name);
fs::write(&file_path, &xml)?;

match xdg_mime(&file_path, self.mode, XdgMimeOperation::Install) {
Ok(_) => {
// keep temp dir in prefix around and the temp file
// because we re-use it when unregistering the mime type.
let _ = temp_dir.into_path();
tracker.registered_mime_files.push(file_path);
}
Err(_) => {
if let Some(parent) = xml_path.parent() {
fs::create_dir_all(parent)?;
}
fs::write(&xml_path, xml)?;
tracker.paths.push(xml_path);
if xdg_mime(&file_path, self.mode, XdgMimeOperation::Install).is_ok() {
// keep temp dir in prefix around and the temp file
// because we re-use it when unregistering the mime type.
let _ = temp_dir.into_path();
tracker.registered_mime_files.push(file_path);
} else {
if let Some(parent) = xml_path.parent() {
fs::create_dir_all(parent)?;
}
fs::write(&xml_path, xml)?;
tracker.paths.push(xml_path);
}

Ok(())
Expand Down Expand Up @@ -746,7 +743,7 @@ mod tests {
for item in &parsed_schema.menu_items {
let icon = item.command.icon.as_ref().unwrap();
for ext in &["icns", "png", "svg"] {
placeholders.insert("ICON_EXT".to_string(), ext.to_string());
placeholders.insert("ICON_EXT".to_string(), (*ext).to_string());
let icon_path = icon.resolve(FakePlaceholders {
placeholders: placeholders.clone(),
});
Expand Down
2 changes: 1 addition & 1 deletion crates/rattler_menuinst/src/linux/mime_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl MimeConfig {
}
}

/// Create a new MimeConfig instance and load the configuration from the given path
/// Create a new `MimeConfig` instance and load the configuration from the given path
pub fn load<P: AsRef<Path>>(path: P) -> Result<Self, std::io::Error> {
let mut this = Self::new(path);

Expand Down
5 changes: 3 additions & 2 deletions crates/rattler_menuinst/src/utils/slugify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ use unicode_normalization::UnicodeNormalization;
/// assert_eq!(slug, "hello-world");
/// ```
pub fn slugify(text: &str) -> String {
static RE_SPECIAL: Lazy<Regex> = Lazy::new(|| Regex::new(r"[^\w\s-]").expect("Invalid regex"));
static RE_SPACES: Lazy<Regex> = Lazy::new(|| Regex::new(r"[_\s-]+").expect("Invalid regex"));

// Normalize the text and remove non-ASCII characters
let normalized = text.nfkd().filter(char::is_ascii).collect::<String>();

// Remove special characters, convert to lowercase, and trim
static RE_SPECIAL: Lazy<Regex> = Lazy::new(|| Regex::new(r"[^\w\s-]").expect("Invalid regex"));
let without_special = RE_SPECIAL.replace_all(&normalized, "").to_string();
let trimmed = without_special.trim().to_lowercase();

// Replace whitespace and hyphens with a single hyphen
static RE_SPACES: Lazy<Regex> = Lazy::new(|| Regex::new(r"[_\s-]+").expect("Invalid regex"));
RE_SPACES.replace_all(&trimmed, "-").to_string()
}

Expand Down
7 changes: 1 addition & 6 deletions crates/rattler_networking/src/mirror_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,7 @@

for (i, mirror) in mirrors.iter().enumerate() {
let failures = mirror.failures.load(atomic::Ordering::Relaxed);
if failures < min_failures
&& mirror
.mirror
.max_failures
.map_or(true, |max| failures < max)
{
if failures < min_failures && mirror.mirror.max_failures.is_none_or(|max| failures < max) {

Check failure on line 89 in crates/rattler_networking/src/mirror_middleware.rs

View workflow job for this annotation

GitHub Actions / Format, Lint and Test the Python bindings

use of unstable library feature 'is_none_or'
min_failures = failures;
min_failures_index = i;
}
Expand Down
Loading