use serde::Deserialize;
use crate::{InfoHash, TorrentID};
use std::path::PathBuf;
pub trait ToTorrent {
fn to_torrent(&self) -> Torrent;
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Torrent {
pub name: String,
pub path: String,
pub date_start: i64,
pub date_end: i64,
pub progress: u8,
pub size: i64,
pub state: String,
pub tags: Vec<String>,
pub hash: InfoHash,
pub id: TorrentID,
}
impl Torrent {
#[allow(dead_code)]
pub(crate) fn dummy_from_hash(hash: &InfoHash) -> Torrent {
Torrent {
name: String::new(),
path: String::new(),
date_start: 0,
date_end: 0,
progress: 0,
size: 0,
state: String::new(),
tags: Vec::new(),
hash: hash.clone(),
id: hash.id(),
}
}
}
pub trait ToTorrentContent {
fn to_torrent_content(&self) -> TorrentContent;
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct TorrentContent {
pub path: PathBuf,
pub size: u64,
}
impl std::cmp::PartialOrd for TorrentContent {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl std::cmp::Ord for TorrentContent {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.path.cmp(&other.path)
}
}