1use errors::Result;
2use std::fmt;
3use {RpPackage, RpRequiredPackage, Source, Version};
4
5#[derive(Debug)]
7pub struct Resolved {
8 pub version: Option<Version>,
10 pub source: Source,
12}
13
14#[derive(Debug)]
16pub struct ResolvedByPrefix {
17 pub package: RpPackage,
19 pub source: Source,
21}
22
23impl Resolved {
24 pub fn from_pair(pair: (Option<Version>, Source)) -> Resolved {
26 let (version, source) = pair;
27
28 Resolved { version, source }
29 }
30}
31
32impl fmt::Display for Resolved {
33 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
34 if let Some(ref version) = self.version {
35 write!(fmt, "{}-{}", self.source, version)
36 } else {
37 self.source.fmt(fmt)
38 }
39 }
40}
41
42pub trait Resolver {
44 fn resolve(&mut self, package: &RpRequiredPackage) -> Result<Vec<Resolved>>;
46
47 fn resolve_by_prefix(&mut self, package: &RpPackage) -> Result<Vec<ResolvedByPrefix>>;
49}
50
51pub struct EmptyResolver;
52
53impl Resolver for EmptyResolver {
54 fn resolve(&mut self, _package: &RpRequiredPackage) -> Result<Vec<Resolved>> {
55 Ok(vec![])
56 }
57
58 fn resolve_by_prefix(&mut self, _package: &RpPackage) -> Result<Vec<ResolvedByPrefix>> {
59 Ok(vec![])
60 }
61}