use crate::Package;
use std::borrow::Borrow;
use std::cmp::Ordering;
use std::collections::HashSet;
use std::hash::{Hash, Hasher};
use std::ops::Deref;
use std::sync::Arc;
pub type Cache = HashSet<ArcPackage>;
#[derive(Clone, Debug, Default)]
pub struct ArcPackage(Arc<Package>);
impl PartialEq for ArcPackage {
fn eq(&self, other: &Self) -> bool {
self.0.name == other.0.name
}
}
impl PartialOrd for ArcPackage {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for ArcPackage {
fn cmp(&self, other: &Self) -> Ordering {
self.0.name.cmp(&other.0.name)
}
}
impl Eq for ArcPackage {}
impl Deref for ArcPackage {
type Target = Package;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Hash for ArcPackage {
fn hash<H: Hasher>(&self, state: &mut H) {
self.0.name.hash(state);
}
}
impl Borrow<str> for ArcPackage {
fn borrow(&self) -> &str {
self.0.name.as_str()
}
}
impl From<Package> for ArcPackage {
fn from(pkg: Package) -> ArcPackage {
ArcPackage(Arc::new(pkg))
}
}
impl ArcPackage {
pub fn new(pkg: Package) -> ArcPackage {
pkg.into()
}
}