Skip to content

Commit

Permalink
Add pointer equality to PartialEq for PackageId
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Nov 26, 2018
1 parent 0abfcc0 commit a73c517
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/cargo/core/package_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
}
Expand Down Expand Up @@ -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()?;
Expand Down

0 comments on commit a73c517

Please sign in to comment.