1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! The dependency view: one declared Cargo edge and how it activates.
use std::sync::Arc;
use super::identity::{PackageId, TargetId};
/// Which Cargo dependency table declared an edge.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum CargoDependencyKind {
/// A `[dependencies]` edge.
Normal,
/// A `[dev-dependencies]` edge.
Development,
/// A `[build-dependencies]` edge.
Build,
}
/// Whether an edge is unconditional, or carries a predicate this model records
/// without evaluating.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DependencyActivation {
/// The edge is active in every configuration.
Always,
/// The edge is active only under the recorded, unevaluated predicate.
Conditional(Arc<str>),
}
/// One dependency edge declared by a package inside the project.
#[derive(Debug)]
pub struct RustDependency {
pub(super) source: PackageId,
pub(super) name: Arc<str>,
pub(super) package_name: Arc<str>,
pub(super) kind: CargoDependencyKind,
pub(super) activation: DependencyActivation,
pub(super) package: Option<PackageId>,
pub(super) library: Option<TargetId>,
}
impl RustDependency {
/// The package that declares this edge.
pub fn source(&self) -> PackageId {
self.source
}
/// The namespace-local dependency name, which a rename may change.
pub fn name(&self) -> &str {
&self.name
}
/// The depended-on package's real Cargo name.
pub fn package_name(&self) -> &str {
&self.package_name
}
/// Which dependency table declared this edge.
pub fn kind(&self) -> CargoDependencyKind {
self.kind
}
/// Whether this edge is always active, and under which predicate otherwise.
pub fn activation(&self) -> &DependencyActivation {
&self.activation
}
/// The in-repository package this edge selects, when it resolves to one.
pub fn package(&self) -> Option<PackageId> {
self.package
}
/// The in-repository library target this edge selects, when one exists.
pub fn library(&self) -> Option<TargetId> {
self.library
}
}