use std::collections::HashSet; use chrono::{DateTime, Utc}; use crate::gentoo::UseFlag; #[derive(Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)] pub struct PackageKey { // Field declaration matters because Ord, and PartialOrd check in order pub category: String, pub name: String, } // impl Ord for PackageKey { // fn cmp(&self, other: &Self) -> std::cmp::Ordering { // let cat_ord = self.category.cmp(&other.category); // if cat_ord == Ordering::Equal { // return self.name.cmp(&other.name); // } // // cat_ord // } // } // // impl PartialOrd for PackageKey { // fn partial_cmp(&self, other: &Self) -> Option { // match self.category.partial_cmp(&other.category) { // Some(core::cmp::Ordering::Equal) => {} // ord => return ord, // } // self.name.partial_cmp(&other.name) // } // } impl PackageKey { pub fn from_atom(s: &str) -> Option { let (category, name) = s.split_once('/')?; Some(Self { category: category.to_string(), name: name.to_string(), }) } pub fn qualified_name(&self) -> String { format!("{}/{}", self.category, self.name) } } #[derive(Debug, Clone, PartialEq, Eq)] pub struct Metadata { pub maintainer: Option, pub description: Option, pub homepage: Vec, pub license: Option, pub repository: String, } #[derive(Debug, Clone)] #[allow(dead_code)] pub struct InstalledPackage { pub atom: PackageKey, pub version: String, pub build_time: DateTime, pub slot: i32, pub metadata: Metadata, pub enabled_use_flags: HashSet, pub iuse: Vec, pub size: usize, } #[derive(Debug)] pub struct Package { pub atom: PackageKey, pub versions: Vec, } #[derive(Debug, Clone, PartialEq, Eq)] pub struct PackageVersion { pub version: String, pub metadata: Metadata, pub keywords: Vec, pub iuse: Vec, } impl PartialOrd for PackageVersion { fn partial_cmp(&self, other: &Self) -> Option { match self.version.partial_cmp(&other.version) { Some(core::cmp::Ordering::Equal) => {} ord => return ord, } self.metadata .repository .partial_cmp(&other.metadata.repository) } } impl Ord for PackageVersion { fn cmp(&self, other: &Self) -> std::cmp::Ordering { self.version.cmp(&other.version) } }