56 lines
1.2 KiB
Rust
56 lines
1.2 KiB
Rust
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)]
|
|
#[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())
|
|
}
|
|
}
|