Start moving methods from Registry to Source
authorDale Wijnand <dale.wijnand@gmail.com>
Thu, 3 May 2018 22:14:21 +0000 (23:14 +0100)
committerDale Wijnand <dale.wijnand@gmail.com>
Fri, 4 May 2018 07:19:40 +0000 (08:19 +0100)
For now just move `supports_checksums` and `requires_precise` methods
down from `Registry` to `Source`, as they're not as entangled as
`query`.

src/cargo/core/registry.rs
src/cargo/core/source/mod.rs
src/cargo/sources/directory.rs
src/cargo/sources/git/source.rs
src/cargo/sources/path.rs
src/cargo/sources/registry/mod.rs
src/cargo/sources/replaced.rs
tests/testsuite/resolve.rs

index ba1866bc897227f58c09f465fa16e3ddb30b1f0c..b219105bff08ce4087a4530194afe77c02347b2c 100644 (file)
@@ -21,28 +21,12 @@ pub trait Registry {
         self.query(dep, &mut |s| ret.push(s))?;
         Ok(ret)
     }
-
-    /// Returns whether or not this registry will return summaries with
-    /// checksums listed.
-    fn supports_checksums(&self) -> bool;
-
-    /// Returns whether or not this registry will return summaries with
-    /// the `precise` field in the source id listed.
-    fn requires_precise(&self) -> bool;
 }
 
 impl<'a, T: ?Sized + Registry + 'a> Registry for Box<T> {
     fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
         (**self).query(dep, f)
     }
-
-    fn supports_checksums(&self) -> bool {
-        (**self).supports_checksums()
-    }
-
-    fn requires_precise(&self) -> bool {
-        (**self).requires_precise()
-    }
 }
 
 /// This structure represents a registry of known packages. It internally
@@ -535,14 +519,6 @@ impl<'cfg> Registry for PackageRegistry<'cfg> {
         f(self.lock(override_summary));
         Ok(())
     }
-
-    fn supports_checksums(&self) -> bool {
-        false
-    }
-
-    fn requires_precise(&self) -> bool {
-        false
-    }
 }
 
 fn lock(locked: &LockedMap, patches: &HashMap<Url, Vec<PackageId>>, summary: Summary) -> Summary {
@@ -703,13 +679,5 @@ pub mod test {
                 Ok(())
             }
         }
-
-        fn supports_checksums(&self) -> bool {
-            false
-        }
-
-        fn requires_precise(&self) -> bool {
-            false
-        }
     }
 }
index b842a5792cfbd4489b19fa90784a1b133800a27a..10418714bffc25caf125429355a7df0873d8ecdc 100644 (file)
@@ -14,6 +14,14 @@ pub trait Source: Registry {
     /// Returns the `SourceId` corresponding to this source
     fn source_id(&self) -> &SourceId;
 
+    /// Returns whether or not this registry will return summaries with
+    /// checksums listed.
+    fn supports_checksums(&self) -> bool;
+
+    /// Returns whether or not this registry will return summaries with
+    /// the `precise` field in the source id listed.
+    fn requires_precise(&self) -> bool;
+
     /// The update method performs any network operations required to
     /// get the entire list of all names, versions and dependencies of
     /// packages managed by the Source.
@@ -52,6 +60,16 @@ impl<'a, T: Source + ?Sized + 'a> Source for Box<T> {
         (**self).source_id()
     }
 
+    /// Forwards to `Source::supports_checksums`
+    fn supports_checksums(&self) -> bool {
+        (**self).supports_checksums()
+    }
+
+    /// Forwards to `Source::requires_precise`
+    fn requires_precise(&self) -> bool {
+        (**self).requires_precise()
+    }
+
     /// Forwards to `Source::update`
     fn update(&mut self) -> CargoResult<()> {
         (**self).update()
index a4d36ead4e2a374431b8a74f422a66c41f735b59..21a167ac1b335f99197213f93dcbf9f25335284d 100644 (file)
@@ -53,6 +53,12 @@ impl<'cfg> Registry for DirectorySource<'cfg> {
         }
         Ok(())
     }
+}
+
+impl<'cfg> Source for DirectorySource<'cfg> {
+    fn source_id(&self) -> &SourceId {
+        &self.source_id
+    }
 
     fn supports_checksums(&self) -> bool {
         true
@@ -61,12 +67,6 @@ impl<'cfg> Registry for DirectorySource<'cfg> {
     fn requires_precise(&self) -> bool {
         true
     }
-}
-
-impl<'cfg> Source for DirectorySource<'cfg> {
-    fn source_id(&self) -> &SourceId {
-        &self.source_id
-    }
 
     fn update(&mut self) -> CargoResult<()> {
         self.packages.clear();
index 98e42310171e3c23b50962c13c197a80f9635e6e..332f37aa24077baed04c0e6c9db1fbdc3fc76b51 100644 (file)
@@ -131,6 +131,12 @@ impl<'cfg> Registry for GitSource<'cfg> {
             .expect("BUG: update() must be called before query()");
         src.query(dep, f)
     }
+}
+
+impl<'cfg> Source for GitSource<'cfg> {
+    fn source_id(&self) -> &SourceId {
+        &self.source_id
+    }
 
     fn supports_checksums(&self) -> bool {
         false
@@ -139,12 +145,6 @@ impl<'cfg> Registry for GitSource<'cfg> {
     fn requires_precise(&self) -> bool {
         true
     }
-}
-
-impl<'cfg> Source for GitSource<'cfg> {
-    fn source_id(&self) -> &SourceId {
-        &self.source_id
-    }
 
     fn update(&mut self) -> CargoResult<()> {
         let lock =
index aa654abee60ab9aa6542b3acaf3d77005cb7836c..e24e4996812dda02a7f8e12ed25d9f781c53e058 100644 (file)
@@ -484,6 +484,12 @@ impl<'cfg> Registry for PathSource<'cfg> {
         }
         Ok(())
     }
+}
+
+impl<'cfg> Source for PathSource<'cfg> {
+    fn source_id(&self) -> &SourceId {
+        &self.source_id
+    }
 
     fn supports_checksums(&self) -> bool {
         false
@@ -492,12 +498,6 @@ impl<'cfg> Registry for PathSource<'cfg> {
     fn requires_precise(&self) -> bool {
         false
     }
-}
-
-impl<'cfg> Source for PathSource<'cfg> {
-    fn source_id(&self) -> &SourceId {
-        &self.source_id
-    }
 
     fn update(&mut self) -> CargoResult<()> {
         if !self.updated {
index 96cce76d460ea30ab898135f016678edc0355486..19c270ab018095a4dce87ff30f9478fc6b403142 100644 (file)
@@ -441,6 +441,12 @@ impl<'cfg> Registry for RegistrySource<'cfg> {
 
         self.index.query(dep, &mut *self.ops, f)
     }
+}
+
+impl<'cfg> Source for RegistrySource<'cfg> {
+    fn source_id(&self) -> &SourceId {
+        &self.source_id
+    }
 
     fn supports_checksums(&self) -> bool {
         true
@@ -449,12 +455,6 @@ impl<'cfg> Registry for RegistrySource<'cfg> {
     fn requires_precise(&self) -> bool {
         false
     }
-}
-
-impl<'cfg> Source for RegistrySource<'cfg> {
-    fn source_id(&self) -> &SourceId {
-        &self.source_id
-    }
 
     fn update(&mut self) -> CargoResult<()> {
         // If we have an imprecise version then we don't know what we're going
index 3f223ef61627079d67be5e48b9b6ba1db1ed37f9..84bab7f54077c1514bbc1607a4c80914b40dfea1 100644 (file)
@@ -34,6 +34,12 @@ impl<'cfg> Registry for ReplacedSource<'cfg> {
             .chain_err(|| format!("failed to query replaced source {}", self.to_replace))?;
         Ok(())
     }
+}
+
+impl<'cfg> Source for ReplacedSource<'cfg> {
+    fn source_id(&self) -> &SourceId {
+        &self.to_replace
+    }
 
     fn supports_checksums(&self) -> bool {
         self.inner.supports_checksums()
@@ -42,12 +48,6 @@ impl<'cfg> Registry for ReplacedSource<'cfg> {
     fn requires_precise(&self) -> bool {
         self.inner.requires_precise()
     }
-}
-
-impl<'cfg> Source for ReplacedSource<'cfg> {
-    fn source_id(&self) -> &SourceId {
-        &self.to_replace
-    }
 
     fn update(&mut self) -> CargoResult<()> {
         self.inner
index e6377a5418af577e9862953f0638a3e3b653166a..4ba61b32191c59128ed3160e9a19b6ada7d09439 100644 (file)
@@ -36,12 +36,6 @@ fn resolve_with_config(
             }
             Ok(())
         }
-        fn supports_checksums(&self) -> bool {
-            false
-        }
-        fn requires_precise(&self) -> bool {
-            false
-        }
     }
     let mut registry = MyRegistry(registry);
     let summary = Summary::new(pkg.clone(), deps, BTreeMap::new(), None, false).unwrap();