use HashSet instead of Vec for file links

This commit is contained in:
2026-03-16 17:08:10 +01:00
parent 74df0d1cc1
commit 55f9e3f6d6
2 changed files with 6 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
use std::ffi::OsStr; use std::{collections::HashSet, ffi::OsStr};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -10,7 +10,7 @@ use crate::{
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
pub struct InstalledMod { pub struct InstalledMod {
id: String, id: String,
files: Vec<Link>, files: HashSet<Link>,
priority: isize, priority: isize,
} }
@@ -18,13 +18,13 @@ impl InstalledMod {
pub fn new(root_mod_id: &str, priority: isize) -> Self { pub fn new(root_mod_id: &str, priority: isize) -> Self {
Self { Self {
id: root_mod_id.to_owned(), id: root_mod_id.to_owned(),
files: Vec::new(), files: HashSet::new(),
priority, priority,
} }
} }
pub fn add_file(&mut self, file: &ModFile) { pub fn add_file(&mut self, file: &ModFile) {
self.files.push(Link::from_mod_file(file)); self.files.insert(Link::from_mod_file(file));
} }
/// Get the id of the mod /// Get the id of the mod
@@ -38,7 +38,7 @@ impl InstalledMod {
} }
/// The selected files /// The selected files
pub fn files(&self) -> &[Link] { pub fn files(&self) -> &HashSet<Link> {
&self.files &self.files
} }

View File

@@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
use crate::types::mod_file::ModFile; use crate::types::mod_file::ModFile;
/// A link between a file from a mod and a destination in a ModdedInstance /// A link between a file from a mod and a destination in a ModdedInstance
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, Hash)]
#[serde(from = "(PathBuf, PathBuf)", into = "(PathBuf,PathBuf)")] #[serde(from = "(PathBuf, PathBuf)", into = "(PathBuf,PathBuf)")]
pub struct Link { pub struct Link {
src: PathBuf, src: PathBuf,