Add pointer equality to PartialEq for PackageId

This commit is contained in:
Dale Wijnand 2018-11-25 14:20:42 +00:00
parent 0abfcc0dd4
commit a73c5171f8
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF

View File

@ -3,6 +3,7 @@ use std::fmt::{self, Formatter};
use std::hash;
use std::hash::Hash;
use std::path::Path;
use std::ptr;
use std::sync::Mutex;
use semver;
@ -18,7 +19,7 @@ lazy_static! {
}
/// Identifier for a specific version of a package in a specific source.
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Clone, Copy, Eq, Hash, PartialOrd, Ord)]
pub struct PackageId {
inner: &'static PackageIdInner,
}
@ -96,6 +97,15 @@ impl<'de> de::Deserialize<'de> for PackageId {
}
}
impl PartialEq for PackageId {
fn eq(&self, other: &PackageId) -> bool {
if ptr::eq(self.inner, other.inner) {
return true;
}
(*self.inner).eq(&*other.inner)
}
}
impl PackageId {
pub fn new<T: ToSemver>(name: &str, version: T, sid: SourceId) -> CargoResult<PackageId> {
let v = version.to_semver()?;