.. and move query definitions to the struct impls.
use std::collections::hash_map::{HashMap, IterMut, Values};
use std::fmt;
-use core::{Package, PackageId, Registry};
+use core::{Dependency, Package, PackageId, Summary};
use util::CargoResult;
mod source_id;
/// A Source finds and downloads remote packages based on names and
/// versions.
-pub trait Source: Registry {
+pub trait Source {
/// Returns the `SourceId` corresponding to this source
fn source_id(&self) -> &SourceId;
- /// Returns whether or not this registry will return summaries with
+ /// Returns whether or not this source will return summaries with
/// checksums listed.
fn supports_checksums(&self) -> bool;
- /// Returns whether or not this registry will return summaries with
+ /// Returns whether or not this source will return summaries with
/// the `precise` field in the source id listed.
fn requires_precise(&self) -> bool;
+ /// Attempt to find the packages that match a dependency request.
+ fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()>;
+
+ fn query_vec(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
+ let mut ret = Vec::new();
+ self.query(dep, &mut |s| ret.push(s))?;
+ Ok(ret)
+ }
+
/// 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.
(**self).requires_precise()
}
+ /// Forwards to `Source::query`
+ fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
+ (**self).query(dep, f)
+ }
+
/// Forwards to `Source::update`
fn update(&mut self) -> CargoResult<()> {
(**self).update()
packages: HashMap::new(),
}
}
+
+ fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
+ let packages = self.packages.values().map(|p| &p.0);
+ let matches = packages.filter(|pkg| dep.matches(pkg.summary()));
+ for summary in matches.map(|pkg| pkg.summary().clone()) {
+ f(summary);
+ }
+ Ok(())
+ }
}
impl<'cfg> Debug for DirectorySource<'cfg> {
impl<'cfg> Registry for DirectorySource<'cfg> {
fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
- let packages = self.packages.values().map(|p| &p.0);
- let matches = packages.filter(|pkg| dep.matches(pkg.summary()));
- for summary in matches.map(|pkg| pkg.summary().clone()) {
- f(summary);
- }
- Ok(())
+ self.query(dep, f)
}
}
true
}
+ fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
+ self.query(dep, f)
+ }
+
fn update(&mut self) -> CargoResult<()> {
self.packages.clear();
let entries = self.root.read_dir().chain_err(|| {
self.remote.url()
}
+ fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
+ let src = self.path_source
+ .as_mut()
+ .expect("BUG: update() must be called before query()");
+ Source::query(src, dep, f)
+ }
+
pub fn read_packages(&mut self) -> CargoResult<Vec<Package>> {
if self.path_source.is_none() {
self.update()?;
impl<'cfg> Registry for GitSource<'cfg> {
fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
- let src = self.path_source
- .as_mut()
- .expect("BUG: update() must be called before query()");
- src.query(dep, f)
+ self.query(dep, f)
}
}
true
}
+ fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
+ self.query(dep, f)
+ }
+
fn update(&mut self) -> CargoResult<()> {
let lock =
self.config
self.packages.push(pkg);
}
+ fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
+ for s in self.packages.iter().map(|p| p.summary()) {
+ if dep.matches(s) {
+ f(s.clone())
+ }
+ }
+ Ok(())
+ }
+
pub fn root_package(&mut self) -> CargoResult<Package> {
trace!("root_package; source={:?}", self);
impl<'cfg> Registry for PathSource<'cfg> {
fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
- for s in self.packages.iter().map(|p| p.summary()) {
- if dep.matches(s) {
- f(s.clone())
- }
- }
- Ok(())
+ self.query(dep, f)
}
}
false
}
+ fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
+ self.query(dep, f)
+ }
+
fn update(&mut self) -> CargoResult<()> {
if !self.updated {
let packages = self.read_packages()?;
}
}
+ fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
+ // If this is a precise dependency, then it came from a lockfile and in
+ // theory the registry is known to contain this version. If, however, we
+ // come back with no summaries, then our registry may need to be
+ // updated, so we fall back to performing a lazy update.
+ if dep.source_id().precise().is_some() && !self.updated {
+ let mut called = false;
+ self.index.query(dep, &mut *self.ops, &mut |s| {
+ called = true;
+ f(s);
+ })?;
+ if called {
+ return Ok(());
+ } else {
+ self.do_update()?;
+ }
+ }
+
+ self.index.query(dep, &mut *self.ops, f)
+ }
+
/// Decode the configuration stored within the registry.
///
/// This requires that the index has been at least checked out.
impl<'cfg> Registry for RegistrySource<'cfg> {
fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
- // If this is a precise dependency, then it came from a lockfile and in
- // theory the registry is known to contain this version. If, however, we
- // come back with no summaries, then our registry may need to be
- // updated, so we fall back to performing a lazy update.
- if dep.source_id().precise().is_some() && !self.updated {
- let mut called = false;
- self.index.query(dep, &mut *self.ops, &mut |s| {
- called = true;
- f(s);
- })?;
- if called {
- return Ok(());
- } else {
- self.do_update()?;
- }
- }
-
- self.index.query(dep, &mut *self.ops, f)
+ self.query(dep, f)
}
}
false
}
+ fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
+ self.query(dep, f)
+ }
+
fn update(&mut self) -> CargoResult<()> {
// If we have an imprecise version then we don't know what we're going
// to look for, so we always attempt to perform an update here.
inner: src,
}
}
-}
-impl<'cfg> Registry for ReplacedSource<'cfg> {
fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
let (replace_with, to_replace) = (&self.replace_with, &self.to_replace);
let dep = dep.clone().map_source(to_replace, replace_with);
}
}
+impl<'cfg> Registry for ReplacedSource<'cfg> {
+ fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
+ self.query(dep, f)
+ }
+}
+
impl<'cfg> Source for ReplacedSource<'cfg> {
fn source_id(&self) -> &SourceId {
&self.to_replace
self.inner.requires_precise()
}
+ fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> {
+ self.query(dep, f)
+ }
+
fn update(&mut self) -> CargoResult<()> {
self.inner
.update()