the great refactor

This commit is contained in:
2026-03-04 22:50:37 +01:00
parent b6efa0a818
commit c81178567a
15 changed files with 519 additions and 448 deletions

55
src/types/link.rs Normal file
View File

@@ -0,0 +1,55 @@
use std::path::{Path, PathBuf};
use serde::{Deserialize, Serialize};
use crate::types::mod_file::ModFile;
/// A link between a file from a mod and a destination in a ModdedInstance
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, Hash)]
#[serde(from = "(PathBuf, PathBuf)", into = "(PathBuf,PathBuf)")]
pub struct Link {
src: PathBuf,
dst: PathBuf,
}
impl Link {
pub fn new(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> Self {
Self {
src: src.as_ref().to_owned(),
dst: dst.as_ref().to_owned(),
}
}
pub fn from_mod_file(file: &ModFile) -> Self {
Self::new(file.src(), file.dst())
}
pub fn src(&self) -> &Path {
&self.src
}
pub fn dst(&self) -> &Path {
&self.dst
}
}
impl From<(PathBuf, PathBuf)> for Link {
fn from(value: (PathBuf, PathBuf)) -> Self {
Self {
src: value.0,
dst: value.1,
}
}
}
impl From<Link> for (PathBuf, PathBuf) {
fn from(value: Link) -> Self {
(value.src, value.dst)
}
}
impl From<ModFile> for Link {
fn from(value: ModFile) -> Self {
Self::new(value.src(), value.dst())
}
}