pedant_core/resolution/rust/snapshot/
unit.rs1use std::fmt;
4use std::sync::Arc;
5
6use crate::resolution::rust::dependency::{CargoDependencyKind, DependencyActivation};
7use crate::resolution::rust::identity::{PackageId, TargetId};
8use crate::resolution::rust::target::CargoTargetKind;
9
10use super::module::RustModuleInstance;
11
12#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
17pub struct RustSnapshotUnitId {
18 index: u32,
19}
20
21impl RustSnapshotUnitId {
22 pub(super) fn new(index: u32) -> Self {
24 Self { index }
25 }
26
27 pub(in crate::resolution::rust) fn index(&self) -> u32 {
29 self.index
30 }
31}
32
33impl fmt::Debug for RustSnapshotUnitId {
34 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
35 write!(formatter, "RustSnapshotUnitId({})", self.index)
36 }
37}
38
39#[derive(Debug)]
41pub struct RustResolutionUnit {
42 pub(super) id: RustSnapshotUnitId,
43 pub(super) package: PackageId,
44 pub(super) target: TargetId,
45 pub(super) name: Arc<str>,
46 pub(super) manifest: Arc<str>,
47 pub(super) kind: CargoTargetKind,
48 pub(super) activation: DependencyActivation,
49 pub(super) crate_root: Arc<str>,
50 pub(super) modules: Box<[RustModuleInstance]>,
51 pub(super) sources: Box<[Arc<str>]>,
52}
53
54impl RustResolutionUnit {
55 pub fn id(&self) -> RustSnapshotUnitId {
57 self.id
58 }
59
60 pub fn package(&self) -> PackageId {
62 self.package
63 }
64
65 pub fn target(&self) -> TargetId {
67 self.target
68 }
69
70 pub fn name(&self) -> &str {
72 &self.name
73 }
74
75 pub fn manifest_path(&self) -> &str {
77 &self.manifest
78 }
79
80 pub fn kind(&self) -> CargoTargetKind {
82 self.kind
83 }
84
85 pub fn activation(&self) -> &DependencyActivation {
88 &self.activation
89 }
90
91 pub fn crate_root(&self) -> &str {
93 &self.crate_root
94 }
95
96 pub fn modules(&self) -> &[RustModuleInstance] {
98 &self.modules
99 }
100
101 pub fn sources(&self) -> &[Arc<str>] {
103 &self.sources
104 }
105}
106
107#[derive(Debug)]
113pub struct RustSnapshotEdge {
114 pub(super) source: RustSnapshotUnitId,
115 pub(super) target: RustSnapshotUnitId,
116 pub(super) name: Arc<str>,
117 pub(super) kind: CargoDependencyKind,
118 pub(super) activation: DependencyActivation,
119}
120
121impl RustSnapshotEdge {
122 pub fn source(&self) -> RustSnapshotUnitId {
124 self.source
125 }
126
127 pub fn target(&self) -> RustSnapshotUnitId {
129 self.target
130 }
131
132 pub fn name(&self) -> &str {
134 &self.name
135 }
136
137 pub fn kind(&self) -> CargoDependencyKind {
139 self.kind
140 }
141
142 pub fn activation(&self) -> &DependencyActivation {
144 &self.activation
145 }
146}