From 1606ab3a79384c330f3d0f52184ec0fd4055a0fc Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Thu, 20 Dec 2018 10:36:43 +0000 Subject: [PATCH] Replace PackageId::wrap with PackageId::pure --- src/cargo/core/package_id.rs | 37 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/cargo/core/package_id.rs b/src/cargo/core/package_id.rs index 9182cb20d54..c25a668e4e9 100644 --- a/src/cargo/core/package_id.rs +++ b/src/cargo/core/package_id.rs @@ -72,6 +72,7 @@ impl<'de> de::Deserialize<'de> for PackageId { let string = String::deserialize(d)?; let mut s = string.splitn(3, ' '); let name = s.next().unwrap(); + let name = InternedString::new(name); let version = match s.next() { Some(s) => s, None => return Err(de::Error::custom("invalid serialized PackageId")), @@ -88,11 +89,7 @@ impl<'de> de::Deserialize<'de> for PackageId { }; let source_id = SourceId::from_url(url).map_err(de::Error::custom)?; - Ok(PackageId::wrap(PackageIdInner { - name: InternedString::new(name), - version, - source_id, - })) + Ok(PackageId::pure(name, version, source_id)) } } @@ -118,15 +115,15 @@ impl<'a> Hash for PackageId { impl PackageId { pub fn new(name: &str, version: T, sid: SourceId) -> CargoResult { let v = version.to_semver()?; - - Ok(PackageId::wrap(PackageIdInner { - name: InternedString::new(name), - version: v, - source_id: sid, - })) + Ok(PackageId::pure(InternedString::new(name), v, sid)) } - fn wrap(inner: PackageIdInner) -> PackageId { + pub fn pure(name: InternedString, version: semver::Version, source_id: SourceId) -> PackageId { + let inner = PackageIdInner { + name, + version, + source_id, + }; let mut cache = PACKAGE_ID_CACHE.lock().unwrap(); let inner = cache.get(&inner).cloned().unwrap_or_else(|| { let inner = Box::leak(Box::new(inner)); @@ -147,19 +144,15 @@ impl PackageId { } pub fn with_precise(self, precise: Option) -> PackageId { - PackageId::wrap(PackageIdInner { - name: self.inner.name, - version: self.inner.version.clone(), - source_id: self.inner.source_id.with_precise(precise), - }) + PackageId::pure( + self.inner.name, + self.inner.version.clone(), + self.inner.source_id.with_precise(precise), + ) } pub fn with_source_id(self, source: SourceId) -> PackageId { - PackageId::wrap(PackageIdInner { - name: self.inner.name, - version: self.inner.version.clone(), - source_id: source, - }) + PackageId::pure(self.inner.name, self.inner.version.clone(), source) } pub fn stable_hash(self, workspace: &Path) -> PackageIdStableHash<'_> {